feat(tools): expose MCP tools through the @tools catalog#1129
Merged
Conversation
The deferred tool catalog left MCP tools in the dark on the text-dispatch path: the system prompt listed only name and description and told the model to invoke blind so the system would echo the schema back. That echo only fires when the tool declares required parameters — a schemaless call to a tool with only optional parameters EXECUTES it as a side effect of discovery — and `@tools describe`/`list` answered "unknown tool" for any `mcp_*` name. Now the catalog covers MCP end to end: - `mcp.Manager.VisibleTools` returns visibility-filtered snapshots honoring `EnabledTools`/`DisabledTools`, sorted by name so the rendered catalog stays stable and cache-friendly across turns. - `@tools describe mcp_<tool>` renders the full block: server, description, parameter JSON Schema and the invocation form. Prefix aliases resolve too, since models drop them routinely, and a builtin with the same bare name still wins. - `@tools list` appends an MCP section with one-line index entries in the same `[MCP:server]` format the system prompt already uses. - The MCP prompt section now routes schema discovery through `@tools describe` instead of blind invocation; the schema echo on a missing-required-params call stays as fallback. Tests pin the visibility filter and ordering, the describe/list/alias/ error surfaces with and without an MCP manager wired, and the new prompt instruction.
Contributor
Quality GateResult: ✅ all floors passed
Config: .github/quality-gate.yml. Workflow: |
Provenance now reads at a glance: entries cluster under one header per server, ordered by server name, while the per-line tag stays for models that quote a single line out of context.
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.
Problema
O catálogo deferred de tools (
@toolsmeta-tool) deixou as tools MCP no escuro no caminho de dispatch textual:@tools describe/listrespondiam unknown tool para qualquer nomemcp_*— o adapter só consultava o plugin registry.Solução
O catálogo agora cobre MCP de ponta a ponta:
mcp.Manager.VisibleTools— snapshots das tools descobertas honrandoEnabledTools/DisabledTools(mesmo filtro deGetTools/GetToolsSummary), ordenados por nome para catálogo estável e cache-friendly entre turnos.@tools describe mcp_<tool>— bloco completo: servidor, descrição, JSON Schema de parâmetros e forma de invocação. Aliases resolvem (@mcp_x, nome bare, case-insensitive) já que modelos derrubam prefixos rotineiramente; builtin com mesmo nome bare continua vencendo. Tool sem parâmetros instrui explicitamenteargs='{}'.@tools list— seção MCP com entradas de uma linha no mesmo formato[MCP:server]que o system prompt já usa; contagem agrega builtins+MCP.@tools describeem vez de invocação cega; o echo de schema em chamada sem required params permanece como fallback.mcp_*disponíveis junto com os builtins.Testes
TestManager_VisibleTools_FilterAndOrder— filtro de visibilidade + ordenação estável (ordem de iteração de map não vaza pro prompt).TestToolCatalogAdapterDescribeMCP— describe com schema completo, aliases, tool schemaless, erro listando nomes MCP, e sessão sem MCP manager (sem panic).TestToolCatalogAdapterListMCP— seção MCP no index, contagem agregada, ausência da seção sem MCP.TestBuildMCPToolsSection— pina a nova instrução@tools describeno prompt.go build ./...,go test ./...egolangci-lint runlimpos.