Skip to content

Commit 6c1efcd

Browse files
committed
feat: update README
1 parent ed525c4 commit 6c1efcd

File tree

1 file changed

+151
-50
lines changed

1 file changed

+151
-50
lines changed

README.md

+151-50
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,206 @@
11
# mcp-framework
22

3-
A framework for building Model Context Protocol (MCP) servers with automatic tool loading and management in Typescript.
3+
A framework for building Model Context Protocol (MCP) servers elegantly in TypeScript.
44

55
Get started fast with mcp-framework ⚡⚡⚡
66

77
## Features
88

9-
- 🛠️ Automatic tool discovery and loading
10-
- 🏗️ Base tool implementation with helper methods
11-
- ⚙️ Configurable tool directory and exclusions
12-
- 🔒 Type-safe tool validation
9+
- 🛠️ Automatic directory-based discovery and loading for tools, prompts, and resources
10+
- 🏗️ Powerful abstractions
1311
- 🚀 Simple server setup and configuration
14-
- 🐛 Built-in error handling and logging
1512

1613
## Installation
1714

1815
```bash
19-
npm install mcp-framework @modelcontextprotocol/sdk
16+
npm install mcp-framework
2017
```
2118

2219
## Quick Start
2320

24-
1. Create your MCP server:
21+
### 1. Create your MCP server:
2522

2623
```typescript
2724
import { MCPServer } from "mcp-framework";
2825

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-
});
26+
const server = new MCPServer();
3427

3528
server.start().catch((error) => {
3629
console.error("Server failed to start:", error);
3730
process.exit(1);
3831
});
3932
```
4033

41-
2. Create a tool by extending BaseToolImplementation:
34+
### 2. Create a Tool:
4235

4336
```typescript
44-
import { BaseToolImplementation } from "mcp-framework";
45-
import { Tool } from "@modelcontextprotocol/sdk/types.js";
37+
import { MCPTool } from "mcp-framework";
38+
import { z } from "zod";
39+
40+
interface ExampleInput {
41+
message: string;
42+
}
4643

47-
class ExampleTool extends BaseToolImplementation {
44+
class ExampleTool extends MCPTool<ExampleInput> {
4845
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-
},
46+
description = "An example tool that processes messages";
47+
48+
schema = {
49+
message: {
50+
type: z.string(),
51+
description: "Message to process",
6052
},
6153
};
6254

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-
}
55+
async execute(input: ExampleInput) {
56+
return `Processed: ${input.message}`;
7557
}
7658
}
7759

7860
export default ExampleTool;
7961
```
8062

81-
## Configuration
63+
### 3. Create a Prompt:
8264

83-
### MCPServer Options
65+
```typescript
66+
import { MCPPrompt } from "mcp-framework";
67+
import { z } from "zod";
68+
69+
interface GreetingInput {
70+
name: string;
71+
language?: string;
72+
}
8473

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)
74+
class GreetingPrompt extends MCPPrompt<GreetingInput> {
75+
name = "greeting";
76+
description = "Generate a greeting in different languages";
8977

90-
### Project Structure
78+
schema = {
79+
name: {
80+
type: z.string(),
81+
description: "Name to greet",
82+
required: true,
83+
},
84+
language: {
85+
type: z.string().optional(),
86+
description: "Language for greeting",
87+
required: false,
88+
},
89+
};
90+
91+
async generateMessages({ name, language = "English" }: GreetingInput) {
92+
return [
93+
{
94+
role: "user",
95+
content: {
96+
type: "text",
97+
text: `Generate a greeting for ${name} in ${language}`,
98+
},
99+
},
100+
];
101+
}
102+
}
103+
104+
export default GreetingPrompt;
105+
```
106+
107+
### 4. Create a Resource:
108+
109+
```typescript
110+
import { MCPResource, ResourceContent } from "mcp-framework";
111+
112+
class ConfigResource extends MCPResource {
113+
uri = "config://app/settings";
114+
name = "Application Settings";
115+
description = "Current application configuration";
116+
mimeType = "application/json";
117+
118+
async read(): Promise<ResourceContent[]> {
119+
const config = {
120+
theme: "dark",
121+
language: "en",
122+
};
123+
124+
return [
125+
{
126+
uri: this.uri,
127+
mimeType: this.mimeType,
128+
text: JSON.stringify(config, null, 2),
129+
},
130+
];
131+
}
132+
}
133+
134+
export default ConfigResource;
135+
```
136+
137+
## Project Structure
91138

92139
```
93140
your-project/
94141
├── src/
95-
│ ├── tools/
96-
│ │ ├── ExampleTool.ts
97-
│ │ └── OtherTool.ts
142+
│ ├── tools/ # Tool implementations
143+
│ │ └── ExampleTool.ts
144+
│ ├── prompts/ # Prompt implementations
145+
│ │ └── GreetingPrompt.ts
146+
│ ├── resources/ # Resource implementations
147+
│ │ └── ConfigResource.ts
98148
│ └── index.ts
99149
├── package.json
100150
└── tsconfig.json
101151
```
102152

153+
## Automatic Feature Discovery
154+
155+
The framework automatically discovers and loads:
156+
157+
- Tools from the `src/tools` directory
158+
- Prompts from the `src/prompts` directory
159+
- Resources from the `src/resources` directory
160+
161+
Each feature should be in its own file and export a default class that extends the appropriate base class:
162+
163+
- `MCPTool` for tools
164+
- `MCPPrompt` for prompts
165+
- `MCPResource` for resources
166+
167+
### Base Classes
168+
169+
#### MCPTool
170+
171+
- Handles input validation using Zod
172+
- Provides error handling and response formatting
173+
- Includes fetch helper for HTTP requests
174+
175+
#### MCPPrompt
176+
177+
- Manages prompt arguments and validation
178+
- Generates message sequences for LLM interactions
179+
- Supports dynamic prompt templates
180+
181+
#### MCPResource
182+
183+
- Exposes data through URI-based system
184+
- Supports text and binary content
185+
- Optional subscription capabilities for real-time updates
186+
187+
## Type Safety
188+
189+
All features use Zod for runtime type validation and TypeScript for compile-time type checking. Define your input schemas using Zod types:
190+
191+
```typescript
192+
schema = {
193+
parameter: {
194+
type: z.string().email(),
195+
description: "User email address",
196+
},
197+
count: {
198+
type: z.number().min(1).max(100),
199+
description: "Number of items",
200+
},
201+
};
202+
```
203+
103204
## License
104205

105206
MIT

0 commit comments

Comments
 (0)