Add optional MCP tool formatter (closes #131)#132
Draft
danielnachumdev wants to merge 1 commit into
Draft
Conversation
Lets MCP tools pipe serialized JSON through an operator-defined shell command at the gateway, with capa sh --json to bypass formatting. Also fixes a flaky registry installer test that hung on slow DNS resolution. Closes infragate#131 Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an optional, operator-configurable post-processing (“formatter”) step for MCP tool outputs at the CAPA gateway, with a CLI escape hatch to request raw JSON output.
Changes:
- Extend MCP tool definitions with optional
def.formatter(cmd, optionaltimeout) and document the schema. - Apply formatter handling across MCP tool-call paths and add
capa sh --jsonto bypass formatting via an internal meta-arg. - Stabilize a previously flaky URL-installer test by using a local HTTP server that returns 503.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/types/capabilities.ts | Adds ToolFormatterDefinition and wires formatter into ToolMCPDefinition. |
| src/shared/registries/tests/installer.test.ts | Replaces DNS-dependent failure test with local 503 server for determinism. |
| src/server/tool-formatter.ts | Introduces formatter plumbing: meta-arg stripping, result serialization, and shell formatter execution. |
| src/server/mcp-handler.ts | Routes tool-call outputs through the new formatter logic and strips the CLI meta-arg from forwarded args. |
| src/server/tests/tool-formatter.test.ts | Adds unit tests for meta stripping, serialization, formatter application, and timeout/failure behavior. |
| src/cli/commands/sh.ts | Adds --json mode and forwards the skip-formatter meta-arg for tool calls. |
| src/cli/commands/tests/sh.test.ts | Adds tests for parseShellGlobalFlags() and --json parsing behavior. |
| skills/capabilities-manager/references/capabilities-schema.md | Documents the new MCP formatter block and the capa sh --json bypass behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+97
to
+113
| const timeout = formatter.timeout ?? DEFAULT_FORMATTER_TIMEOUT_MS; | ||
| const isWindows = process.platform === 'win32'; | ||
| const shell = isWindows ? 'cmd.exe' : '/bin/sh'; | ||
| const shellFlag = isWindows ? '/C' : '-c'; | ||
|
|
||
| return new Promise((resolve) => { | ||
| let settled = false; | ||
| const finish = (value: string) => { | ||
| if (settled) return; | ||
| settled = true; | ||
| resolve(value); | ||
| }; | ||
|
|
||
| const proc = spawn(shell, [shellFlag, formatter.cmd], { | ||
| stdio: ['pipe', 'pipe', 'pipe'], | ||
| windowsHide: true, | ||
| }); |
Comment on lines
+82
to
+87
| it('returns transformed stdout on success', async () => { | ||
| const out = await applyToolFormatter('{"name":"alice"}', { | ||
| cmd: "jq -r '.name'", | ||
| }); | ||
| expect(out).toBe('alice'); | ||
| }); |
| import type { Capabilities } from '../../types/capabilities'; | ||
| import { getQualifiedToolName } from '../../types/capabilities'; | ||
| import { slugify } from '../../shared/slug'; | ||
| import { CAPA_JSON_ARG } from '../../server/tool-formatter'; |
Member
|
Thanks for the PR @danielnachumdev! Can you change the target branch to Besides that, please address the Copilot comments. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
formatterblock to MCP tool definitions (def.formatter.cmd, optionaltimeout) so serialized tool output can be piped through operator-defined shell commands at the CAPA gateway before returning to clientscapa sh --jsonto skip formatting and return raw JSON (uses internal_capa_jsonmeta-arg, stripped server-side)installer — url installstest that hung on slow DNS by using a local server returning 503Example
Verified
bun test src/server/__tests__/tool-formatter.test.ts— 12 passedbun test src/cli/commands/__tests__/sh.test.ts— 41 passedbun test— 1125 passedbun run build— succeeded (dist/capa)Made with Cursor