https://github.com/brooswit/node-mcp-server
Easy plug-and-play MCP server
https://github.com/brooswit/node-mcp-server
Last synced: 30 days ago
JSON representation
Easy plug-and-play MCP server
- Host: GitHub
- URL: https://github.com/brooswit/node-mcp-server
- Owner: brooswit
- Created: 2025-08-09T23:13:09.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-08-09T23:26:07.000Z (10 months ago)
- Last Synced: 2025-08-10T01:12:13.211Z (10 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## @brooswit/node-mcp-server
Minimal, embeddable MCP server core for Node.js. Provides JSON-RPC 2.0 handling, tool registry, and tool invocation for the Model Context Protocol (MCP).
### Install
- As a local workspace package or via file reference. No external runtime deps.
### API
- **McpServer class**
- `constructor()` - Create server instance
- `register(specLoader)` - Register a tool spec loader function
- specLoader: () => Promise<{ MCP_TOOL_SPECS?: ToolSpec[] }>
- `start()` - Initialize the server and pre-build tool registry
- `handle(request)` - Handle JSON-RPC requests
- `listTools()` - Get available tools
- **constants**
- JSONRPC_VERSION
- JSONRPC_METHOD_INITIALIZE, JSONRPC_METHOD_TOOLS_LIST, JSONRPC_METHOD_TOOLS_CALL
- JSONRPC_ERROR_* codes
- MCP_PROTOCOL_VERSION, MCP_SERVER_NAME, MCP_SERVER_VERSION
### ToolSpec shape
```
interface ToolSpec {
name: string;
description: string;
inputSchema: Record;
params: string[];
fn: (...args: any[]) => Promise | any;
}
```
### Example
```js
import { McpServer, JSONRPC_METHOD_TOOLS_LIST } from '@brooswit/node-mcp-server';
const server = new McpServer();
server.register(() => import('./my-tools.mjs'));
await server.start();
const resp = await server.handle({ jsonrpc: '2.0', id: 1, method: JSONRPC_METHOD_TOOLS_LIST });
console.log(resp);
```
### Notes
- Call `register()` to add tool spec loaders, then `start()` to initialize the registry.
- Duplicate tool names are de-duped by first occurrence.
- Results are wrapped for broad MCP client compatibility: strings become text items; objects are JSON-stringified unless already shaped as an MCP tool result.