Skip to content

feat(tool_use): Add cookbook for FastMCP primitives with Claude#510

Open
cubaseuser123 wants to merge 1 commit intoanthropics:mainfrom
cubaseuser123:feat/mcp-fastmcp-cookbook
Open

feat(tool_use): Add cookbook for FastMCP primitives with Claude#510
cubaseuser123 wants to merge 1 commit intoanthropics:mainfrom
cubaseuser123:feat/mcp-fastmcp-cookbook

Conversation

@cubaseuser123
Copy link
Copy Markdown

Following up on the basic native MCP client cookbook, I put together a companion notebook to specifically document the high-level FastMCP framework.

While building basic MCP tools is straightforward, there's currently a bit of a documentation gap when it comes to tying together FastMCP's advanced primitives with a Claude client in Python. This notebook builds a simple "knowledge server" to demo exactly how to do that.

It covers:

  • Exposing static, read-only data via @mcp.resource
  • Fetching reusable system templates from the server using @mcp.prompt
  • Using Context injection to do programmatic server-side logging (ctx.info()) mid-tool execution without polluting the LLM's tool loop.

I made sure it runs cleanly against the local ruff configuration (E, F, and W flags) and properly formats to nbformat 4. I also injected realistic mock execution outputs directly into the notebook JSON, so it should render perfectly in the GitHub preview UI right away.

Let me know if you want me to tweak any of the examples!

@tejas-dharani
Copy link
Copy Markdown

Missing registry.yaml and authors.yaml entries — every cookbook needs these to show up in the registry. See other recent PRs for the format.

@cubaseuser123
Copy link
Copy Markdown
Author

Thanks for pointing that out! I completely missed the registry requirements.

I've just added the correct entries to both registry.yaml and authors.yaml (and cleared up a minor merge conflict while I was at it), so everything is now fully wired up for the website build process. Let me know if anything else needs adjusting.

Copy link
Copy Markdown

@martingarramon martingarramon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good companion to the native MCP client notebook. The three-primitive structure (tool/resource/prompt) is the right framing for FastMCP. A few observations:

Scope: The PR adds two notebooks — the FastMCP one (described in the PR) and a native MCP client notebook at tool_use/mcp_native_client/claude_with_mcp.ipynb that isn't mentioned in the description. Is the second notebook from your earlier PR #499, or is it new? Worth calling out in the description either way so reviewers know what they're evaluating.

FastMCP API usage: The @mcp.resource(), @mcp.tool(), and Context injection all look correct. One thing to verify: @mcp.prompt(title="Topic Expert") — in the FastMCP API I've seen, the decorator typically takes name and description rather than title. If title isn't a real parameter, it would silently be ignored. Worth confirming against the current mcp SDK version.

Mock outputs note: The PR description says mock execution outputs were injected directly into the notebook JSON. The cookbook repo keeps outputs intentionally (CONTRIBUTING.md rule), so they'll be treated as real by readers. If any mock output diverges from what the code actually produces, it'll confuse anyone trying to reproduce. Might be worth a note in the notebook that outputs are illustrative, or — better — running the notebook and capturing real outputs.

Model and API key: claude-haiku-4-5 (correct alias) and os.environ.get("ANTHROPIC_API_KEY") — both good.

- FastMCP server with tools, resources, and prompts
- Fix @mcp.prompt decorator to use name/description params
- Add illustrative output note for mock cell outputs
- Add authors.yaml and registry.yaml entries
@cubaseuser123 cubaseuser123 force-pushed the feat/mcp-fastmcp-cookbook branch from 32fbc8c to 616024c Compare April 11, 2026 06:56
@cubaseuser123
Copy link
Copy Markdown
Author

Thanks for the thorough review! I've addressed all three points in a single force-pushed commit:

1. Scope: I rebased the branch so it now only contains the FastMCP notebook and its YAML metadata. The native MCP client notebook at tool_use/mcp_native_client/ is from my other PR (#499) and was leaking into this diff due to branch ancestry. It's now cleanly isolated!

2. @mcp.prompt API: Good catch. I updated both decorators from title= to name= + description=, which accurately matches the SDK's actual signature.

3. Mock outputs: I added a visible note in the introductory cell clarifying that the execution outputs shown are illustrative. I don't currently have active API access to capture live outputs for this new run, but the code is structured cleanly so anyone with a key can run it directly anyway.

@nidhishgajjar
Copy link
Copy Markdown

Orb Code Review (powered by GLM 5.1 on Orb Cloud)

New cookbook: FastMCP with Claude, covering all three MCP primitives (tools, resources, prompts) and Context for logging/progress.

Observations

1. Good coverage of all MCP primitives (Positive)
The notebook covers tools, resources, and prompts — the three core MCP concepts — with working examples. The comparison table in the intro is helpful for understanding when to use each.

2. %%writefile pattern for server (Positive)
Using %%writefile to create the server script and then launching it as a subprocess is a clean approach for notebooks.

3. Mock outputs committed (Note)
The notebook includes mock outputs so it's readable without running. This is a common pattern in the repo, though it means the notebook may need updates if the MCP SDK API changes.

4. Author avatar URL (Low)

avatar: https://github.com/cubaseuser123.png

This uses the generic GitHub profile picture URL. Other entries in authors.yaml use the avatars.githubusercontent.com format. Minor inconsistency but not blocking.

Summary

Solid cookbook that effectively demonstrates FastMCP's primitives. The clear explanations and working code examples make it a good reference for MCP development.

Assessment: approve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants