|
| 1 | +--- |
| 2 | +description: |
| 3 | +globs: |
| 4 | +alwaysApply: false |
| 5 | +--- |
| 6 | +We are in the mcp-framework , a typescript framework that allows construction of model context protocol (mcp) servers. |
| 7 | +We are implementing the new specification: |
| 8 | +<specification>Overview |
| 9 | +MCP provides a standardized way for applications to: |
| 10 | + |
| 11 | +Share contextual information with language models |
| 12 | +Expose tools and capabilities to AI systems |
| 13 | +Build composable integrations and workflows |
| 14 | +The protocol uses JSON-RPC 2.0 messages to establish communication between: |
| 15 | + |
| 16 | +Hosts: LLM applications that initiate connections |
| 17 | +Clients: Connectors within the host application |
| 18 | +Servers: Services that provide context and capabilities |
| 19 | +MCP takes some inspiration from the Language Server Protocol, which standardizes how to add support for programming languages across a whole ecosystem of development tools. In a similar way, MCP standardizes how to integrate additional context and tools into the ecosystem of AI applications. |
| 20 | + |
| 21 | +Key Details |
| 22 | +Base Protocol |
| 23 | +JSON-RPC message format |
| 24 | +Stateful connections |
| 25 | +Server and client capability negotiation |
| 26 | +Features |
| 27 | +Servers offer any of the following features to clients: |
| 28 | + |
| 29 | +Resources: Context and data, for the user or the AI model to use |
| 30 | +Prompts: Templated messages and workflows for users |
| 31 | +Tools: Functions for the AI model to execute</specification> |
| 32 | + |
| 33 | +Here is an example of how a user creats an mcp server using mcp-framework as the library: <example>## src/tools/ExampleTool.ts |
| 34 | + |
| 35 | +```ts |
| 36 | +import { MCPTool } from "mcp-framework"; |
| 37 | +import { z } from "zod"; |
| 38 | + |
| 39 | +interface ExampleInput { |
| 40 | + message: string; |
| 41 | +} |
| 42 | + |
| 43 | +class ExampleTool extends MCPTool<ExampleInput> { |
| 44 | + name = "example_tool"; |
| 45 | + description = "An example tool that processes messages"; |
| 46 | + |
| 47 | + schema = { |
| 48 | + message: { |
| 49 | + type: z.string(), |
| 50 | + description: "Message to process", |
| 51 | + }, |
| 52 | + }; |
| 53 | + |
| 54 | + async execute(input: ExampleInput) { |
| 55 | + return `Processed: ${input.message}`; |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +export default ExampleTool; |
| 60 | +``` |
| 61 | + |
| 62 | +## src/index.ts |
| 63 | + |
| 64 | +```ts |
| 65 | +import { MCPServer } from "mcp-framework"; |
| 66 | + |
| 67 | +const server = new MCPServer({transport:{ |
| 68 | + type:"http-stream", |
| 69 | + options:{ |
| 70 | + port:1337, |
| 71 | + cors: { |
| 72 | + allowOrigin:"*" |
| 73 | + } |
| 74 | + } |
| 75 | +}}); |
| 76 | + |
| 77 | +server.start(); |
| 78 | + |
| 79 | +``` |
| 80 | + |
| 81 | +## package.json |
| 82 | + |
| 83 | +```json |
| 84 | +{ |
| 85 | + "name": "http2-hi", |
| 86 | + "version": "0.0.1", |
| 87 | + "description": "http2-hi MCP server", |
| 88 | + "type": "module", |
| 89 | + "bin": { |
| 90 | + "http2-hi": "./dist/index.js" |
| 91 | + }, |
| 92 | + "files": [ |
| 93 | + "dist" |
| 94 | + ], |
| 95 | + "scripts": { |
| 96 | + "build": "tsc && mcp-build", |
| 97 | + "watch": "tsc --watch", |
| 98 | + "start": "node dist/index.js" |
| 99 | + }, |
| 100 | + "dependencies": { |
| 101 | + "mcp-framework": "^0.2.12-beta.4", |
| 102 | + "zod": "^3.24.4" |
| 103 | + }, |
| 104 | + "devDependencies": { |
| 105 | + "@types/node": "^20.11.24", |
| 106 | + "typescript": "^5.3.3" |
| 107 | + }, |
| 108 | + "engines": { |
| 109 | + "node": ">=18.19.0" |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +``` |
| 114 | +</example> |
| 115 | + |
| 116 | +It's important to keep in mind that mcp-framework is used exclusively as a dependency in other repositories - just like express js would be. |
| 117 | +This means that we are running it from node_modules within the repo - this impacts how relative directories work |
0 commit comments