mcpdoc

repository·main·Indexed 21 days ago

https://github.com/langchain-ai/mcpdoc

An open-source Model Context Protocol (MCP) server that provides LLM-friendly documentation context by serving llms.txt files. It includes a `fetch_docs` tool to retrieve content from defined sources, allowing developers to control the context provided to AI agents in IDEs and desktop apps. Supports stdio and SSE transports, and can be integrated with Cursor, Windsurf, Claude Desktop, and Claude Code.

Tokens
4.6K
Snippets
17
Records
21
Agent score
76%

What's inside mcpdoc

  1. Security and Domain Access Control in mcpdoc

    main

    To prevent unauthorized access to domains, mcpdoc implements strict domain access controls:

    1. Remote llms.txt files: When you specify a remote URL (e.g., https://langchain-ai.github.io/langgraph/llms.txt), mcpdoc automatically adds only that specific domain (langchain-ai.github.io) to the allowed domains list.
    2. Local llms.txt files: When using a local file, NO domains are automatically added. You MUST explicitly specify allowed domains using the --allowed-domains parameter.
    3. Adding additional domains:
      • Use --allowed-domains domain1.com domain2.com to add specific domains.
      • Use --allowed-domains '*' to allow all domains (use with caution).
  2. Connect mcpdoc to Claude Desktop

    main

    To use mcpdoc in Claude Desktop:

    1. Open Settings/Developer to update ~/Library/Application\ Support/Claude/claude_desktop_config.json.
    2. Add the server configuration using stdio transport.

    Note on Python Compatibility: If you encounter Python version issues, explicitly specify the path to your Python executable using the --python flag in the args.

    {
      "mcpServers": {
        "langgraph-docs-mcp": {
          "command": "uvx",
          "args": [
            "--python",
            "/path/to/python",
            "--from",
            "mcpdoc",
            "mcpdoc",
            "--urls",
            "LangGraph:https://langchain-ai.github.io/langgraph/llms.txt",
            "--transport",
            "stdio"
          ]
        }
      }
    }
    1. Restart Claude Desktop.
    2. Note: As of 3/21/25, Claude Desktop may not support global rules. You may need to append instructions to your prompt using <rules> tags:
    <rules>
    for ANY question about LangGraph, use the langgraph-docs-mcp server to help answer -- 
    + call list_doc_sources tool to get the available llms.txt file
    + call fetch_docs tool to read it
    + reflect on the urls in llms.txt 
    + reflect on the input question 
    + call fetch_docs on any urls relevant to the question
    </rules>
  3. Connect mcpdoc to Windsurf

    main

    To use mcpdoc in Windsurf:

    1. Open Cascade with CMD+L (Mac).
    2. Click Configure MCP to open ~/.codeium/windsurf/mcp_config.json.
    3. Add the server configuration (similar to the Cursor config).
    4. Update Windsurf Rules/Global rules with instructions for the agent:
    for ANY question about LangGraph, use the langgraph-docs-mcp server to help answer -- 
    + call list_doc_sources tool to get the available llms.txt file
    + call fetch_docs tool to read it
    + reflect on the urls in llms.txt 
    + reflect on the input question 
    + call fetch_docs on any urls relevant to the question
  4. Connect mcpdoc to Claude Code

    main

    To add the mcpdoc server to Claude Code, run the following command in your terminal:

    claude mcp add-json langgraph-docs '{"type":"stdio","command":"uvx" ,"args":["--from", "mcpdoc", "mcpdoc", "--urls", "langgraph:https://langchain-ai.github.io/langgraph/llms.txt", "LangChain:https://python.langchain.com/llms.txt"]}' -s local

    To verify the tools are available, launch Claude Code and run:

    /mcp

    Note: As of 3/21/25, you may need to append instructions to your prompt using <rules> tags to ensure the agent uses the tools correctly.

  5. Connect mcpdoc to Cursor

    main

    To use mcpdoc in Cursor:

    1. Open Cursor Settings and navigate to the MCP tab to edit ~/.cursor/mcp.json.
    2. Add the server configuration. Use stdio transport for Cursor:
    {
      "mcpServers": {
        "langgraph-docs-mcp": {
          "command": "uvx",
          "args": [
            "--from",
            "mcpdoc",
            "mcpdoc",
            "--urls",
            "LangGraph:https://langchain-ai.github.io/langgraph/llms.txt LangChain:https://python.langchain.com/llms.txt",
            "--transport",
            "stdio"
          ]
        }
      }
    }
    1. Best Practice: Update your Cursor Global (User) rules (Settings/Rules) to instruct the agent on how to use the tools:
    for ANY question about LangGraph, use the langgraph-docs-mcp server to help answer -- 
    + call list_doc_sources tool to get the available llms.txt file
    + call fetch_docs tool to read it
    + reflect on the urls in llms.txt 
    + reflect on the input question 
    + call fetch_docs on any urls relevant to the question
    + use this to answer the question
  6. Configure documentation sources in YAML or JSON

    main

    The mcpdoc server is configured using a list of documentation sources in either YAML or JSON format. Each source entry must include an llms_txt URL pointing to the documentation's llms.txt file. You may optionally include a name field to identify the source.

    Required field:

    • llms_txt: The URL of the documentation's llms.txt file.

    Optional field:

    • name: A human-readable name for the documentation source.
    # YAML Example
    - name: LangGraph Python
      llms_txt: https://langchain-ai.github.io/langgraph/llms.txt
    // JSON Example
    [
      {
        "name": "LangGraph Python",
        "llms_txt": "https://langchain-ai.github.io/langgraph/llms.txt"
      }
    ]
  7. Test the MCP server locally with SSE transport

    main

    You can test the mcpdoc server locally using uvx with the SSE transport. This allows you to run the server on a specific port and host for inspection.

    uvx --from mcpdoc mcpdoc \
        --urls "LangGraph:https://langchain-ai.github.io/langgraph/llms.txt" "LangChain:https://python.langchain.com/llms.txt" \
        --transport sse \
        --port 8082 \
        --host localhost

    After running, you can use the MCP inspector to connect and test tool calls:

    npx @modelcontextprotocol/inspector
  8. Use create_server() to initialize the MCP server programmatically

    main

    You can initialize and run the mcpdoc server within a Python application using create_server. This function accepts a list of documentation source dictionaries and optional parameters for network behavior.

    Parameters:

    • sources (list[dict]): A list of dictionaries, where each dictionary contains llms_txt (required) and optionally name.
    • follow_redirects (bool, optional): Whether to follow HTTP redirects when fetching documentation.
    • timeout (float, optional): The timeout in seconds for network requests.

    After creation, call .run(transport="stdio") to start the server using standard input/output transport.

    from mcpdoc.main import create_server
    
    # Create a server with documentation sources
    server = create_server(
        [
            {
                "name": "LangGraph Python",
                "llms_txt": "https://langchain-ai.github.io/langgraph/llms.txt",
            },
        ],
        follow_redirects=True,
        timeout=15.0,
    )
    
    # Run the server
    server.run(transport="stdio")
  9. mcpdoc CLI Options

    main

    The following additional options are available for the mcpdoc CLI:

    OptionDescription
    --follow-redirectsFollow HTTP redirects (defaults to False)
    --timeout SECONDSHTTP request timeout in seconds (defaults to 10.0)

    Example usage:

    mcpdoc --yaml sample_config.yaml --follow-redirects --timeout 15
  10. Use the mcpdoc CLI to launch the server

    main

    The mcpdoc command provides a CLI to launch the documentation server. You can specify documentation sources using YAML, JSON, or direct URLs.

    1. Using a YAML config file:

    mcpdoc --yaml sample_config.yaml

    2. Using a JSON config file:

    mcpdoc --json sample_config.json

    3. Directly specifying URLs: URLs can be plain or formatted as name:url. You can use the --urls parameter multiple times to add multiple sources.

    mcpdoc --urls LangGraph:https://langchain-ai.github.io/langgraph/llms.txt --urls LangChain:https://python.langchain.com/llms.txt

    Combining methods: You can merge sources by using multiple flags:

    mcpdoc --yaml sample_config.yaml --json sample_config.json --urls LangGraph:https://langchain-ai.github.io/langgraph/llms.txt
  11. Use get_docs() to retrieve LangGraph documentation

    main

    The get_docs tool allows you to fetch LangGraph documentation from langchain-ai.github.io in markdown format.

    Important Usage Pattern: You should always fetch the overview URL first. The overview response provides a list of available URLs that you can subsequently use to fetch specific documentation pages.

    Arguments:

    • url (str): The specific URL to fetch. It must either be the string "overview" or a valid URL starting with https://langchain-ai.github.io/.
    # Example of how the tool is invoked via MCP
    # 1. Get the overview to find available URLs
    overview_content = await get_docs(url="overview")
    
    # 2. Use a URL from the overview to get specific docs
    # (Assuming 'https://langchain-ai.github.io/langgraph/concepts' was in the overview)
    specific_docs = await get_docs(url="https://langchain-ai.github.io/langgraph/concepts")