Skip to content
This repository was archived by the owner on May 21, 2026. It is now read-only.

Commit a25db00

Browse files
committed
refactor: rename standalone server example to simple and update dependencies
- Changed the directory name from `standalone` to `simple` in the workspace configuration. - Updated dependencies in `pnpm-lock.yaml`, including removing `@types/bun` and adjusting TypeScript version. - Modified CLI to use `stdio: 'inherit'` for better output handling. - Enhanced resource definition in `mcp-server.ts` to include metadata fields. - Updated resource definition interface in `types.ts` to improve documentation and structure.
1 parent 21c9fc4 commit a25db00

9 files changed

Lines changed: 169 additions & 55 deletions

File tree

packages/cli/src/index.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,25 +155,11 @@ program
155155
// 3. Server with tsx
156156
const serverProc = spawn('npx', ['tsx', 'watch', serverFile], {
157157
cwd: projectPath,
158-
stdio: 'pipe',
158+
stdio: 'inherit',
159159
shell: false,
160160
env: { ...process.env, PORT: String(port) },
161161
});
162162

163-
// Handle server errors gracefully
164-
serverProc.stderr?.on('data', (data) => {
165-
const output = data.toString();
166-
if (output.includes('EADDRINUSE')) {
167-
console.log(`\x1b[31m✗\x1b[0m Port ${port} is still in use. Please try a different port with --port`);
168-
console.log(`\x1b[90mHint: Use --port 3001 or kill the process using port ${port}\x1b[0m`);
169-
process.exit(1);
170-
}
171-
});
172-
173-
serverProc.stdout?.on('data', (data) => {
174-
process.stdout.write(data);
175-
});
176-
177163
processes.push(serverProc);
178164

179165
// Auto-open inspector if enabled
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Simple MCP Server Example
2+
3+
A minimal example of an MCP server with a single "hello world" tool.
4+
5+
## Features
6+
7+
- Single `hello-world` tool that returns "Hello World!"
8+
- MCP Inspector integration
9+
- TypeScript support
10+
- Simple and easy to understand
11+
12+
## Getting Started
13+
14+
### Development
15+
16+
```bash
17+
# Install dependencies
18+
yarn install
19+
20+
# Start development server
21+
yarn dev
22+
```
23+
24+
This will start:
25+
- MCP server on port 3000
26+
- MCP Inspector at http://localhost:3000/inspector
27+
28+
### Production
29+
30+
```bash
31+
# Build the server
32+
yarn build
33+
34+
# Run the built server
35+
yarn start
36+
```
37+
38+
## Usage
39+
40+
The server provides one tool:
41+
42+
- `hello-world` - Returns "Hello World!" message
43+
44+
## Project Structure
45+
46+
```
47+
simple-example/
48+
├── src/
49+
│ └── server.ts # MCP server with hello world tool
50+
├── dist/ # Built files
51+
├── package.json
52+
├── tsconfig.json
53+
└── README.md
54+
```
55+
56+
## API Reference
57+
58+
### MCP Tools
59+
60+
- `hello-world` - A simple tool that returns hello world
61+
62+
## Learn More
63+
64+
- [MCP Documentation](https://modelcontextprotocol.io)
65+
- [mcp-use Documentation](https://docs.mcp-use.io)

packages/mcp-use/examples/server/standalone/package.json renamed to packages/mcp-use/examples/server/simple/package.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
{
2-
"name": "standalone-mcp-example",
2+
"name": "simple-example",
33
"type": "module",
44
"version": "1.0.0",
5-
"description": "Standalone MCP server example",
5+
"description": "Simple MCP server example with hello world tool",
6+
"author": "",
7+
"license": "MIT",
8+
"keywords": [
9+
"mcp",
10+
"server",
11+
"example",
12+
"hello-world"
13+
],
614
"main": "dist/server.js",
715
"scripts": {
816
"build": "mcp-use build",
@@ -14,8 +22,8 @@
1422
},
1523
"devDependencies": {
1624
"@mcp-use/cli": "workspace:*",
17-
"@mcp-use/inspector": "workspace:*",
18-
"@types/bun": "latest",
19-
"typescript": "^5.3.3"
25+
"@types/node": "^20.0.0",
26+
"tsx": "^4.0.0",
27+
"typescript": "^5.0.0"
2028
}
21-
}
29+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
})
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2022",
4+
"module": "ESNext",
5+
"moduleResolution": "node",
6+
"allowSyntheticDefaultImports": true,
7+
"esModuleInterop": true,
8+
"allowJs": true,
9+
"strict": true,
10+
"skipLibCheck": true,
11+
"forceConsistentCasingInFileNames": true,
12+
"declaration": true,
13+
"outDir": "./dist",
14+
"rootDir": "./src"
15+
},
16+
"include": ["src/**/*"],
17+
"exclude": ["node_modules", "dist"]
18+
}

packages/mcp-use/src/server/mcp-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class McpServer {
9595
this.server.resource(
9696
resourceDefinition.name,
9797
resourceDefinition.uri,
98-
resourceDefinition.resource,
98+
{mimeType: resourceDefinition.mimeType, description: resourceDefinition.description},
9999
async () => {
100100
return await resourceDefinition.fn()
101101
},

packages/mcp-use/src/server/types.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@ export interface ResourceTemplateDefinition {
2222
}
2323

2424
export interface ResourceDefinition {
25+
/** Unique identifier for the resource */
2526
name: string
27+
/** URI pattern for accessing the resource (e.g., 'config://app-settings') */
2628
uri: string
27-
resource: {
28-
title?: string
29-
description?: string
30-
mimeType: string
31-
}
29+
/** Resource metadata including MIME type and description */
30+
/** Optional title for the resource */
31+
title?: string
32+
/** Optional description of the resource */
33+
description?: string
34+
/** MIME type of the resource content (required) */
35+
mimeType: string
36+
/** Async function that returns the resource content */
3237
fn: ResourceHandler
3338
}
3439

pnpm-lock.yaml

Lines changed: 8 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
packages:
22
- 'packages/*'
33
- 'packages/mcp-use/examples/client/react'
4-
- 'packages/mcp-use/examples/server/standalone'
4+
- 'packages/mcp-use/examples/server/simple'
55
- 'test_app'

0 commit comments

Comments
 (0)