#!/usr/bin/env node // 测试用的本地 MCP 服务(stdio):在沙箱中运行,报告环境与文件访问情况 import fs from 'node:fs' import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js' import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js' import { z } from 'zod' const server = new McpServer({ name: 'fixture-stdio', version: '1.0.0' }) server.registerTool('whoami', { description: '报告沙箱环境', inputSchema: {}, annotations: { readOnlyHint: true } }, async () => ({ content: [{ type: 'text', text: JSON.stringify({ secret: process.env.FIXTURE_SECRET ?? null, home: process.env.HOME, cwd: process.cwd() }) }], })) server.registerTool('read_file', { description: '读取文件', inputSchema: { path: z.string() }, annotations: { readOnlyHint: true } }, async ({ path }) => { try { return { content: [{ type: 'text', text: fs.readFileSync(path, 'utf8').slice(0, 200) }] } } catch (err) { return { content: [{ type: 'text', text: `ERR ${err.code}` }], isError: true } } }) await server.connect(new StdioServerTransport())