Skip to content

Comments

Add MCP spec-compliant _meta field to tool results#2

Open
tbtmuse wants to merge 2 commits intoglommer:mainfrom
tbtmuse:feature/mcp-meta-field
Open

Add MCP spec-compliant _meta field to tool results#2
tbtmuse wants to merge 2 commits intoglommer:mainfrom
tbtmuse:feature/mcp-meta-field

Conversation

@tbtmuse
Copy link

@tbtmuse tbtmuse commented Feb 20, 2026

Motivation

I use OpenCode with cachebro and it's been awesome for saving tokens. However, OpenCode has a file write protection feature that ensures files are read before they can be modified (FileTime validation). When using cachebro to read files, OpenCode would still show the error:

"You must read file X before overwriting it. Use the Read tool first"

This happened because OpenCode couldn't detect that cachebro had already read the file.

Proposed solution

Add MCP spec-compliant _meta field to cachebro's read_file and read_files tool results to indicate which files were read:

{
  content: [{ type: text, text: file content }],
  _meta: {
    io.github.glommer.cachebro/files: [/path/to/file.ts]
  }
}

This enables MCP clients like OpenCode to track file reads for validation (e.g., FileTime checks) in a spec-compliant way.

Changes

  • Add _meta field to read_file and read_files tools
  • Returns files read: { "io.github.glommer.cachebro/files": ["/path"] }
  • Add test/mcp-meta.test.ts
  • Rename test/smoke.ts to test/smoke.test.ts for Bun conventions since there are now multiple tests (a little quality of life thing)
  • Update package.json test script to use auto-discovery (also a little quality of life thing)
  • Update CI to run all tests

Testing

All tests pass

- Add _meta field to read_file and read_files tools
- Returns files read: { "io.github.glommer.cachebro/files": ["/path"] }
- Dynamic namespace detection from package.json.mcpName
- Add test/mcp-meta.test.ts with 7 tests
- Rename test/smoke.ts to test/smoke.test.ts for Bun conventions
- Update package.json test script to use auto-discovery
- Update CI to run all tests

This enables MCP clients like OpenCode to track file reads
for validation (e.g., FileTime checks) in a spec-compliant way.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant