|
| 1 | +# mcp-framework |
| 2 | + |
| 3 | +A framework for building Model Context Protocol (MCP) servers with automatic tool loading and management in Typescript. |
| 4 | + |
| 5 | +Get started fast with mcp-framework ⚡⚡⚡ |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- 🛠️ Automatic tool discovery and loading |
| 10 | +- 🏗️ Base tool implementation with helper methods |
| 11 | +- ⚙️ Configurable tool directory and exclusions |
| 12 | +- 🔒 Type-safe tool validation |
| 13 | +- 🚀 Simple server setup and configuration |
| 14 | +- 🐛 Built-in error handling and logging |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +```bash |
| 19 | +npm install mcp-framework @modelcontextprotocol/sdk |
| 20 | +``` |
| 21 | + |
| 22 | +## Quick Start |
| 23 | + |
| 24 | +1. Create your MCP server: |
| 25 | + |
| 26 | +```typescript |
| 27 | +import { MCPServer } from "mcp-framework"; |
| 28 | + |
| 29 | +const server = new MCPServer({ |
| 30 | + name: "my-mcp-server", |
| 31 | + version: "1.0.0", |
| 32 | + toolsDir: "./dist/tools", // Optional: defaults to dist/tools |
| 33 | +}); |
| 34 | + |
| 35 | +server.start().catch((error) => { |
| 36 | + console.error("Server failed to start:", error); |
| 37 | + process.exit(1); |
| 38 | +}); |
| 39 | +``` |
| 40 | + |
| 41 | +2. Create a tool by extending BaseToolImplementation: |
| 42 | + |
| 43 | +```typescript |
| 44 | +import { BaseToolImplementation } from "mcp-framework"; |
| 45 | +import { Tool } from "@modelcontextprotocol/sdk/types.js"; |
| 46 | + |
| 47 | +class ExampleTool extends BaseToolImplementation { |
| 48 | + name = "example_tool"; |
| 49 | + toolDefinition: Tool = { |
| 50 | + name: this.name, |
| 51 | + description: "An example tool", |
| 52 | + inputSchema: { |
| 53 | + type: "object", |
| 54 | + properties: { |
| 55 | + input: { |
| 56 | + type: "string", |
| 57 | + description: "Input parameter", |
| 58 | + }, |
| 59 | + }, |
| 60 | + }, |
| 61 | + }; |
| 62 | + |
| 63 | + async toolCall(request: any) { |
| 64 | + try { |
| 65 | + const input = request.params.arguments?.input; |
| 66 | + if (!input) { |
| 67 | + throw new Error("Missing input parameter"); |
| 68 | + } |
| 69 | + |
| 70 | + const result = `Processed: ${input}`; |
| 71 | + return this.createSuccessResponse(result); |
| 72 | + } catch (error) { |
| 73 | + return this.createErrorResponse(error); |
| 74 | + } |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +export default ExampleTool; |
| 79 | +``` |
| 80 | + |
| 81 | +## Configuration |
| 82 | + |
| 83 | +### MCPServer Options |
| 84 | + |
| 85 | +- `name`: Server name |
| 86 | +- `version`: Server version |
| 87 | +- `toolsDir`: Directory containing tool files (optional) |
| 88 | +- `excludeTools`: Array of patterns for files to exclude (optional) |
| 89 | + |
| 90 | +### Project Structure |
| 91 | + |
| 92 | +``` |
| 93 | +your-project/ |
| 94 | +├── src/ |
| 95 | +│ ├── tools/ |
| 96 | +│ │ ├── ExampleTool.ts |
| 97 | +│ │ └── OtherTool.ts |
| 98 | +│ └── index.ts |
| 99 | +├── package.json |
| 100 | +└── tsconfig.json |
| 101 | +``` |
| 102 | + |
| 103 | +## License |
| 104 | + |
| 105 | +MIT |
0 commit comments