harness-mcp

harness-mcp

A TypeScript boilerplate for building MCP servers with harness engineering, providing tool definitions, structured errors, and evaluation harnesses.

Category
访问服务器

README

harness-mcp

An opinionated TypeScript boilerplate for building MCP servers with harness engineering in mind.

Harness engineering is the discipline of designing the scaffolding around an LLM agent — tools, descriptions, errors, context — so the agent actually does the right thing. Most MCP boilerplates teach you the protocol. This one teaches you the protocol and the practice.

What's in the box

  • defineTool() — one Zod schema feeds the MCP SDK, OpenAI's function-calling API, and the runtime handler. Validation and error wrapping are automatic.
  • Both transports — stdio (src/index.ts) for Claude Code-style local clients, Streamable HTTP (src/http.ts) for remote/web clients. Both share one createServer().
  • Structured AgentErrors — every error has a code, a message, and a hint written for the model: "call items_list first to find a valid id." Vague errors waste turns; this fixes that at the type level.
  • A real eval harness — Vitest-based. Unit tests run free in CI; tests/mcp/echo.test.ts drives a real OpenAI model through the MCP server via an in-memory transport pair and asserts on the resulting tool-call trace.
  • A simple CRUD exampleitems_create / list / read / update / delete plus an echo tool. Replace the in-memory store with your real backend; keep the shape.

Quick start

bun install
bun test              # unit tests, no API key needed
bun run start         # stdio server on stdin/stdout
bun run start:http    # HTTP server on http://localhost:3000/mcp

To run the model-in-the-loop evals:

cp .env.example .env
# add OPENAI_API_KEY
bun run test:mcp

Wire into Claude Code

{
  "mcpServers": {
    "harness-mcp": {
      "command": "bun",
      "args": ["run", "/absolute/path/to/harness/mcp/src/index.ts"]
    }
  }
}

Layout

src/
  index.ts              stdio entry
  http.ts               streamable-http entry
  core/
    server.ts           createServer() — shared by both transports
    tool.ts             defineTool() wrapper
    errors.ts           AgentError
    store.ts            replace with your backend
  tools/
    echo.ts             smoke-test tool
    items-*.ts          CRUD example tools
    index.ts            registry

tests/
  unit/                 fast, no API key
    tool.test.ts
    store.test.ts
  mcp/                  protocol + model-in-the-loop
    setup.ts            in-memory client + runWithModel() helper
    smoke.test.ts       no model
    echo.test.ts        gpt-4o-mini, skipped without OPENAI_API_KEY

The opinions

  1. Tool descriptions are prompt engineering. Every description leads with USE WHEN ... and includes DO NOT USE WHEN ... for sibling tools the model could confuse this with. The smoke test enforces the convention.
  2. Errors teach. Every AgentError carries a hint field. Read your error messages as if you were the agent — would you know what to do next? If not, rewrite.
  3. List endpoints paginate. items_list returns { items, nextCursor }. Default limit 20, hard cap 100. Don't dump unbounded data into the context.
  4. Destructive ops accept dryRun. items_delete will tell you what would happen if you weren't sure.
  5. One Zod, three consumers. Don't maintain JSON Schema by hand alongside Zod — defineTool derives both.
  6. Evals are tests. Tool-call traces are assertable. When a description regression breaks the model's behavior, your test catches it.

License

MIT.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选