feat: add Resources and Prompts primitive examples#16
Merged
Conversation
Brings MCP primitive coverage up to parity with the TS sibling (mcp-server-starter): adds a server-info Resource and a code-review Prompt alongside the existing greet Tool, so the starter now demonstrates all three MCP primitives out of the box. - resources/server_info.py exposes info://server/status as JSON with name/version (read from pyproject.toml via tomllib) plus Python + platform runtime info. - prompts/code_review.py uses pydantic @validate_call to reject empty code and unsupported languages before the handler runs, rendering a single user message with a language-labeled fenced code block. - tests cover identity metadata, registration on the server, handler shape, and pydantic validation failures (14 tests total, all green). - README.md and README.ko.md gain Resources/Prompts sections and the tree diagram now reflects the new modules.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Brings MCP primitive coverage up to parity with the TS sibling (mcp-server-starter). The starter now demonstrates all three MCP primitives out of the box:
greet(unchanged)server-infoatinfo://server/statuscode-reviewwith pydantic-validated argsChanges
Resources (
src/my_mcp_server/resources/server_info.py)@mcp.resource(uri, *, name, title, description, mime_type)decorator, handler returnsstr(JSON) — FastMCP takes care of wrapping into the MCPcontentsenvelope.pyproject.tomlviatomllib(walks up from the source file), with animportlib.metadatafallback for wheel installs where the source tree isn't shipped.sys.version), platform (platform.system()), and arch (platform.machine()).Prompts (
src/my_mcp_server/prompts/code_review.py)@mcp.prompt(name, title, description)wrapping a function whose signature defines the argsSchema; return type islist[UserMessage].@validate_call:language: Literal["py","js","ts","go"]andcode: Annotated[str, Field(min_length=1)]. Empty code and unsupported languages raiseValidationErrorbefore the handler body runs.```py).Tests (14 total, all green locally)
tests/test_server_info.py— identity metadata, JSON shape, version matchespyproject.toml, Python runtime matchessys.version, resource is registered on the server.tests/test_code_review.py— identity metadata, rejects empty code / unsupported language / missing fields, happy-path message shape, per-enum language label interpolation, prompt is registered on the server.Test audit (Task D)
test_greetby changing the handler's return to"Greetings, ". Both existingtest_tools.pytests failed as expected — these are real behavioral assertions, not tautologies or file-existence checks. Reverted.pyproject.tomlalready hastestpaths = ["tests"]withasyncio_mode = "auto"and does not use--passWithNoTests-style masking.README
Adding Resources/Adding Promptssections (English) and the Korean equivalents, plus Resources/Prompts bullets under "What You Get". The project tree diagram inREADME.mdnow showsresources/andprompts/modules and the two new test files.FastMCP API shape used
Test plan
pytest -v— 14 passedruff check .— all checks passedruff format --check .— formattedmypy src/— no issues (9 source files)mcp.list_tools()/list_resources()/list_prompts()/read_resource()/get_prompt()all return the expected shapes