|
| 1 | +import { createMCPServer } from 'mcp-use' |
| 2 | + |
| 3 | +// Create an MCP server (which is also an Express app) |
| 4 | +// The MCP Inspector is automatically mounted at /inspector |
| 5 | +const server = createMCPServer('simple-example-server', { |
| 6 | + version: '1.0.0', |
| 7 | + description: 'A simple MCP server example', |
| 8 | +}) |
| 9 | + |
| 10 | +console.log('Server type:', typeof server) |
| 11 | +console.log('Server has tool method:', 'tool' in server) |
| 12 | +console.log('Server tool method:', typeof server.tool) |
| 13 | +console.log('Server keys:', Object.keys(server)) |
| 14 | +console.log('Server prototype:', Object.getOwnPropertyNames(Object.getPrototypeOf(server))) |
| 15 | + |
| 16 | + |
| 17 | +const PORT = process.env.PORT || 3000 |
| 18 | + |
| 19 | +// Simple tool that returns hello world |
| 20 | +server.tool({ |
| 21 | + name: 'hello-world', |
| 22 | + description: 'A simple tool that returns hello world', |
| 23 | + inputs: [], |
| 24 | + fn: async () => { |
| 25 | + return { |
| 26 | + content: [ |
| 27 | + { |
| 28 | + type: 'text', |
| 29 | + text: 'Hello World!' |
| 30 | + } |
| 31 | + ] |
| 32 | + } |
| 33 | + }, |
| 34 | +}) |
| 35 | + |
| 36 | +server.resource({ |
| 37 | + name: 'test', |
| 38 | + uri: 'resource://test', |
| 39 | + mimeType: 'text/plain', |
| 40 | + description: 'A test resource', |
| 41 | + fn: async () => { |
| 42 | + return 'ciao' |
| 43 | + } |
| 44 | +}) |
| 45 | + |
| 46 | +// Start the server (MCP endpoints auto-mounted at /mcp) |
| 47 | +server.listen(PORT, () => { |
| 48 | + console.log(`🚀 Simple Example Server running on port ${PORT}`) |
| 49 | + console.log(`📊 Inspector available at http://localhost:${PORT}/inspector`) |
| 50 | + console.log(`🔧 MCP endpoint at http://localhost:${PORT}/mcp`) |
| 51 | +}) |
0 commit comments