[Python] When would you need to define your own custom MCP client?

Discussão em 'Python' iniciado por Stack, Julho 26, 2025.

  1. Stack

    Stack Membro Participativo

    I'm new to MCP. Particularly im looking to implement an agentic service using FastMCP in python. From what I understood from the docs the llm (whatever api/sdk/framework your using) is the client as most of the major ones support mcp (e.g. anthropic messages api). As in you do not need to do something like this:

    import asyncio
    from fastmcp import Client, FastMCP

    # In-memory server (ideal for testing)
    server = FastMCP("TestServer")
    client = Client(server) # <- this is what im referring to

    async def main():
    async with client:
    # Basic server interaction
    await client.ping()

    # List available operations
    tools = await client.list_tools()
    resources = await client.list_resources()
    prompts = await client.list_prompts()

    # Execute operations
    result = await client.call_tool("example_tool", {"param": "value"})
    print(result)

    asyncio.run(main())


    Instead you would do something like this

    import anthropic
    from rich import print

    # Your server URL (replace with your actual URL)
    url = 'https://your-server-url.com'

    client = anthropic.Anthropic()

    response = client.beta.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1000,
    messages=[{"role": "user", "content": "Roll a few dice!"}],
    mcp_servers=[
    {
    "type": "url",
    "url": f"{url}/mcp/",
    "name": "dice-server",
    }
    ],
    extra_headers={
    "anthropic-beta": "mcp-client-2025-04-04"
    }
    )

    print(response.content)


    Where I interpret the above as that the anthropic messages API is the client, you don't need to explicitly define client = Client(server)

    So I'm wondering what scenarios you would need to explicitly define your own mcp client when working with llms. (I can see the use of a client if you need to verify responses from servers but wondering about other cases). I may just be misunderstanding it entirely so would appreciate clarification

    Continue reading...

Compartilhe esta Página