[GH-ISSUE #440] Document how to filter MCP tools by name/ metadata #49

Open
opened 2026-02-17 17:19:04 -05:00 by yindo · 4 comments
Owner

Originally created by @marcofiocco on GitHub (Aug 6, 2025).
Original GitHub issue: https://github.com/langchain-ai/docs/issues/440

Implement something like "RAG-MCP: Mitigating Prompt Bloat in LLM Tool Selection via Retrieval-Augmented Generation"
https://arxiv.org/abs/2505.03275

Originally created by @marcofiocco on GitHub (Aug 6, 2025). Original GitHub issue: https://github.com/langchain-ai/docs/issues/440 Implement something like "RAG-MCP: Mitigating Prompt Bloat in LLM Tool Selection via Retrieval-Augmented Generation" https://arxiv.org/abs/2505.03275
yindo added the langchainexternal labels 2026-02-17 17:19:04 -05:00
Author
Owner

@pamelafox commented on GitHub (Aug 20, 2025):

I am filtering MCP server tools using this code:


async def _get_mcp_tools(allow: set[str] | None = None, require: bool = False) -> list[Any]:
    """Fetch MCP tools from the GitHub server.

    - allow: if provided, only return tools whose name is in this set.
    - require: when True, raise if any tool in `allow` is missing.
    """
    client = MultiServerMCPClient(
        {
            "github": {
                "url": "https://api.githubcopilot.com/mcp/",
                "transport": "streamable_http",
                "headers": {
                    "Authorization": f"Bearer {token}",
                },
            }
        }
    )
    all_tools = cast(list[Any], await client.get_tools())
    if allow is None:
        return all_tools

    available_names = {
        name for name in (getattr(t, "name", None) for t in all_tools) if isinstance(name, str)
    }
    missing = {n for n in allow if n not in available_names}
    if require and missing:
        raise RuntimeError(f"Missing required MCP tools: {sorted(missing)}")
    return [t for t in all_tools if getattr(t, "name", None) in allow]

Maybe this should be baked into the package itself, a filtering ability? Not sure whether it'd be better to do at the Client level or the get_tools level. I am happy to send a PR if there's interest from the maintainers.

@pamelafox commented on GitHub (Aug 20, 2025): I am filtering MCP server tools using this code: ``` async def _get_mcp_tools(allow: set[str] | None = None, require: bool = False) -> list[Any]: """Fetch MCP tools from the GitHub server. - allow: if provided, only return tools whose name is in this set. - require: when True, raise if any tool in `allow` is missing. """ client = MultiServerMCPClient( { "github": { "url": "https://api.githubcopilot.com/mcp/", "transport": "streamable_http", "headers": { "Authorization": f"Bearer {token}", }, } } ) all_tools = cast(list[Any], await client.get_tools()) if allow is None: return all_tools available_names = { name for name in (getattr(t, "name", None) for t in all_tools) if isinstance(name, str) } missing = {n for n in allow if n not in available_names} if require and missing: raise RuntimeError(f"Missing required MCP tools: {sorted(missing)}") return [t for t in all_tools if getattr(t, "name", None) in allow] ``` Maybe this should be baked into the package itself, a filtering ability? Not sure whether it'd be better to do at the Client level or the get_tools level. I am happy to send a PR if there's interest from the maintainers.
Author
Owner

@sombaner commented on GitHub (Aug 21, 2025):

This is nice . I am assuming this can be used while developing an agent from scratch. Can this be integrated while using GitHub Copilot agent mode or even coding agent ?

@sombaner commented on GitHub (Aug 21, 2025): This is nice . I am assuming this can be used while developing an agent from scratch. Can this be integrated while using GitHub Copilot agent mode or even coding agent ?
Author
Owner

@pamelafox commented on GitHub (Aug 23, 2025):

@sombaner When using GitHub Copilot coding agent mode, you can select the "tools" button in bottom right and specify exactly what tools you want to use from each MCP server.

Image

You can also write custom chat modes with restricted toolsets:

description: 'Fix and verify issues in app'
model: GPT-5 (Preview)
tools: ['extensions', 'codebase', 'usages', 'vscodeAPI', 'problems', 'changes', 'testFailure', 'fetch', 'findTestFiles', 'searchResults', 'githubRepo', 'runTests', 'runCommands', 'runTasks', 'editFiles', 'runNotebooks', 'search', 'new', 'create_pull_request', 'get_issue', 'get_issue_comments', 'get-library-docs', 'playwright', 'pylance mcp server']
---

But this is unrelated to this Langchain MCP adapters repo, so if you have further questions on GitHub Copilot MCP tool restrictions, I suggest posting in the GitHub community.

@pamelafox commented on GitHub (Aug 23, 2025): @sombaner When using GitHub Copilot coding agent mode, you can select the "tools" button in bottom right and specify exactly what tools you want to use from each MCP server. <img width="1164" height="960" alt="Image" src="https://github.com/user-attachments/assets/7430f5be-ffbd-4049-8784-f50e54fc04a5" /> You can also write custom chat modes with restricted toolsets: ``` description: 'Fix and verify issues in app' model: GPT-5 (Preview) tools: ['extensions', 'codebase', 'usages', 'vscodeAPI', 'problems', 'changes', 'testFailure', 'fetch', 'findTestFiles', 'searchResults', 'githubRepo', 'runTests', 'runCommands', 'runTasks', 'editFiles', 'runNotebooks', 'search', 'new', 'create_pull_request', 'get_issue', 'get_issue_comments', 'get-library-docs', 'playwright', 'pylance mcp server'] --- ``` But this is unrelated to this Langchain MCP adapters repo, so if you have further questions on GitHub Copilot MCP tool restrictions, I suggest posting in the GitHub community.
Author
Owner

@eyurtsev commented on GitHub (Sep 9, 2025):

At the moment, this can be done client side. @pamelafox if you're interested in contributing a documentation PR to the docs we'll appreciate it!

https://github.com/langchain-ai/docs/blob/main/src/oss/langchain/mcp.mdx

Tools have names and also metadata. The metadata will include both annotations and _meta defined by the server. (the _meta change was just merged on master)

@eyurtsev commented on GitHub (Sep 9, 2025): At the moment, this can be done client side. @pamelafox if you're interested in contributing a documentation PR to the docs we'll appreciate it! https://github.com/langchain-ai/docs/blob/main/src/oss/langchain/mcp.mdx Tools have names and also metadata. The metadata will include both annotations and `_meta` defined by the server. (the _meta change was just merged on master)
yindo changed title from Document how to filter MCP tools by name/ metadata to [GH-ISSUE #440] Document how to filter MCP tools by name/ metadata 2026-06-05 17:24:46 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/docs#49