Summary audio
No audio recap for this lesson.
Study notes
Overview
- Shifting focus from server to client implementation in mcp_client. py
- This project uniquely implements both client and server (typically you'd use one or the other)
- Client allows access to server functionality from the rest of the codebase
MCPClient Class Purpose
- Wraps a client_session (the actual connection to the MCP server)
- Client session is part of the MCP Python SDK
- Manages resource cleanup through connect(), async_enter(), and async_exit() functions
- Wrapping the session in a class simplifies resource management
Client Responsibilities
- Exposes server functionality to the codebase
- Gets list of tools to send to Claude
- Executes tools requested by Claude
- Other code in the core/ directory calls client functions like list_tools(), call_tool(), list_prompts(), get_prompt()
Key Functions to Implement
list_tools()
- Returns await self. session. list_tools()
- Returns result. tools to get all available tools from the server
- Provides tool definitions (name, description, input schema) to Claude
call_tool()
- Returns await self. session. call_tool(tool_name, tool_input)
- Takes tool name and input parameters from Claude
- Executes the tool on the server and returns results
Testing
- Testing harness at bottom of file allows running mcp_client. py directly
- Can verify tools are accessible and callable
- Once implemented, other code can use these functions to enable Claude to inspect and edit documents
Takeaways
- MCPClient wraps a client_session to manage the connection to the MCP server and simplify resource cleanup
- The client exposes server functionality to the codebase through functions like list_tools(), call_tool(), list_prompts(), and get_prompt()
- list_tools() returns available tool definitions (name, description, input schema) to send to Claude
- call_tool() executes tools requested by Claude by calling the server with the tool name and input parameters
- A testing harness at the bottom of the file allows direct verification that tools are accessible and callable
Flashcards 10 cards
Question
click to reveal · ←/→
Answer
click to flip back
Knowledge check 1 questions