Add MCP smoke test client
This commit is contained in:
@@ -43,7 +43,7 @@ npm install
|
||||
Run:
|
||||
|
||||
```bash
|
||||
node mcp_server.mjs
|
||||
npm run mcp
|
||||
```
|
||||
|
||||
If the `m2pack` binary is not at `build/m2pack`, set:
|
||||
@@ -62,6 +62,12 @@ Exposed tools:
|
||||
- `pack_export_client_config`
|
||||
- `pack_binary_info`
|
||||
|
||||
Smoke test:
|
||||
|
||||
```bash
|
||||
npm run mcp:smoke
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
```bash
|
||||
|
||||
17
docs/mcp.md
17
docs/mcp.md
@@ -19,7 +19,7 @@ cd /path/to/m2pack-secure
|
||||
npm install
|
||||
cmake -S . -B build
|
||||
cmake --build build -j
|
||||
node mcp_server.mjs
|
||||
npm run mcp
|
||||
```
|
||||
|
||||
## Environment
|
||||
@@ -78,6 +78,21 @@ Inputs:
|
||||
|
||||
No input. Returns the active `m2pack` binary path.
|
||||
|
||||
## Smoke test
|
||||
|
||||
Run a local roundtrip test with the bundled Node MCP client:
|
||||
|
||||
```bash
|
||||
npm run mcp:smoke
|
||||
```
|
||||
|
||||
That test:
|
||||
|
||||
- spawns `mcp_server.mjs`
|
||||
- connects over stdio
|
||||
- lists tools
|
||||
- calls `pack_binary_info`
|
||||
|
||||
## Claude Desktop style config example
|
||||
|
||||
```json
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"mcp": "node mcp_server.mjs",
|
||||
"mcp:smoke": "node scripts/mcp_smoke_test.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@modelcontextprotocol/sdk": "^1.29.0",
|
||||
"zod": "^3.25.76"
|
||||
|
||||
50
scripts/mcp_smoke_test.mjs
Normal file
50
scripts/mcp_smoke_test.mjs
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env node
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const repoRoot = path.resolve(__dirname, "..");
|
||||
|
||||
async function main() {
|
||||
const client = new Client({
|
||||
name: "m2pack-smoke-test",
|
||||
version: "0.1.0",
|
||||
});
|
||||
|
||||
const transport = new StdioClientTransport({
|
||||
command: "node",
|
||||
args: [path.join(repoRoot, "mcp_server.mjs")],
|
||||
cwd: repoRoot,
|
||||
env: {
|
||||
...process.env,
|
||||
M2PACK_BINARY: process.env.M2PACK_BINARY || path.join(repoRoot, "build", "m2pack"),
|
||||
},
|
||||
stderr: "inherit",
|
||||
});
|
||||
|
||||
await client.connect(transport);
|
||||
|
||||
const tools = await client.listTools();
|
||||
const binaryInfo = await client.callTool({
|
||||
name: "pack_binary_info",
|
||||
arguments: {},
|
||||
});
|
||||
|
||||
console.log(JSON.stringify({
|
||||
ok: true,
|
||||
tool_count: tools.tools.length,
|
||||
tool_names: tools.tools.map((tool) => tool.name),
|
||||
binary_info: binaryInfo.structuredContent ?? null,
|
||||
}, null, 2));
|
||||
|
||||
await transport.close();
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user