Skip to content

MCP vs API: rename folder to match slug and sync code with the article - #850

Open
realpython-bot wants to merge 1 commit into
masterfrom
mcp-vs-api-materials
Open

realpython-bot wants to merge 1 commit into
masterfrom
mcp-vs-api-materials

Conversation

@realpython-bot

@realpython-bot realpython-bot commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Consolidates the two open PRs on this folder (#819 and #832) into a single mergeable change, so there is one PR to review rather than three states of the same five files.

What's here

1. Rename mcp-vs-api-calls/mcp-vs-api/ to match the tutorial slug. This is #819's change, minus its stray root-level uv.lock (3 lines, master has no root lockfile — it looks accidental).

2. Sync the client code with the tech review on realpython/tutorial-drafts#1184. Both clients now:

  • collect every tool_use block, append the assistant turn once, and return all results in a single user message, instead of appending per block
  • select the final text block by type — next(b.text for b in final.content if b.type == "text") — rather than final.content[0].text, which crashes when the model returns a thinking block first
  • use max_tokens=2048, since thinking tokens come out of the same budget

This is #832's intent.

3. Repair two defects in #832 that would have shipped to readers:

  • client_api.py did not parse — an orphaned fragment of the old main() was left below if __name__ == "__main__": (SyntaxError: unexpected indent)
  • client.py had a duplicated if __name__ == "__main__": block, so it launched the server and ran the whole conversation twice

4. README points at the correct tutorial URL (/mcp-vs-api/) and the pinned install command.

server.py and tool.py are unchanged — rename only.

Verification

  • All four scripts parse, and each file's non-blank lines match the article's code blocks line for line
  • ruff check passes; ruff format --check reports all five files already formatted
  • mcp-vs-api satisfies dircheck's folder-name rule

Opt-in

CMS Optin 1283's download_url now points at .../tree/master/mcp-vs-api/, so it resolves automatically when this merges — the same pattern as the other in-flight tutorials, whose opt-ins also 404 until their materials land. Nothing to do at merge time.

Supersedes #819 and #832. The code changes are @leriomaggio's work.


🤖 Opened by Claude Code (RPBot) on Stephen's behalf, with his permission. The review decisions behind it are his.

Consolidates the two open PRs on this folder into one.

- Renames mcp-vs-api-calls/ to mcp-vs-api/ to match the tutorial slug
  (supersedes #819, minus its stray root-level uv.lock).
- Syncs client.py and client_api.py with the tech-review changes in
  tutorial-drafts#1184: collect every tool_use block and append the
  assistant turn once, select the text block by type rather than
  position, and raise max_tokens to 2048 (supersedes #832).
- Repairs the leftover fragments in #832: client_api.py did not parse,
  and client.py ran its __main__ block twice.
- Points the README at the correct tutorial URL and the pinned install
  command.

Code verified line-for-line against the article. ruff check and
ruff format pass.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

1 participant