Skip to content

Add a minimal Python MCP client example - #72

Open
ShlokShar wants to merge 1 commit into
jonashertner:mainfrom
ShlokShar:issuesieve/issue-62-19
Open

Add a minimal Python MCP client example#72
ShlokShar wants to merge 1 commit into
jonashertner:mainfrom
ShlokShar:issuesieve/issue-62-19

Conversation

@ShlokShar

Copy link
Copy Markdown

Add a small runnable Python example that connects to the hosted MCP server, calls search_decisions, and prints the returned German citation strings.

Fixes #62

@jonashertner

Copy link
Copy Markdown
Owner

Thank you for this — first contribution to the new issue set, and the structure is right: it's small, runnable, has no dependency on a local corpus, and the README link lands in the correct section.

I ran it against production before reviewing, and it exits 0 but prints nothing. The cause is a genuine wrinkle in our API that the issue text didn't warn you about, so this is our documentation gap rather than a mistake on your part.

search_decisions returns formatted Markdown text, not JSON, and no structuredContent:

content types: ['TextContent']
structuredContent: none
text begins: 'Found 1206 decisions (showing 1–3):\n\n**1.** [BGE 125 III 70](https://...) (1998-10-13) [bge] [de]'

So json.loads(text) never runs (the text doesn't start with { or [), _extract_results receives a plain string and returns [], and the loop prints nothing.

Two ways to fix it, and I'd prefer the second:

Option A — print the text. Drop the JSON handling and print the tool's own formatted output. Honest and three lines shorter, but it doesn't demonstrate reading a specific field, which was the point of the example.

Option B — use cite for the citation strings. Parse the decision links out of the search text, then call cite for each one. cite does return JSON, with a citation_string_de field. That also demonstrates the rule that matters most here: citation strings are copied from a stored field, never assembled. This is what I'd merge.

Either way, two smaller points:

  1. Endpoint. sse_client needs the /sse path — https://mcp.opencaselaw.ch/sse, not the bare host. It happens to work today, but the documented endpoints are /mcp (streamable-http, preferred) and /sse.
  2. Silent success. Consider exiting non-zero, or printing a message, when zero citations are found. A script that prints nothing and returns 0 is hard to distinguish from a broken connection — which is exactly what happened here.

I've also opened this as a documentation fix on our side: the text-versus-JSON split across tools isn't written down anywhere, and you're the second consumer to hit it.

Happy to take this in either shape — say which you'd prefer and I'll review promptly.

@jonashertner

Copy link
Copy Markdown
Owner

Thank you for this — and for picking up a good first issue. The structure is right and the transport works. One thing blocks it, which I verified by running your file as-is:

$ python examples/python/minimal_mcp_client.py "missbräuchliche Kündigung"
$ echo $?
0

Exit 0, no output. The cause is that search_decisions returns Markdown, not JSON, so _extract_results finds no results/items/decisions/data key and the loop has nothing to print. There is a second, smaller issue behind it: _extract_content_text handles str and dict, but the SDK yields TextContent objects, so text is empty and the code falls through to model_dump(), which JSON-dumps the envelope rather than the payload.

Two ways to finish it, either is fine:

  1. Keep search_decisions and print what it returns — add getattr(part, "text", "") to _extract_content_text and print the Markdown directly. Simplest, and honest about the tool’s shape.
  2. Switch the demo to a JSON tool so the "print the citation strings" promise holds literally. cite returns a JSON object with citation_string_de/_fr/_it, e.g. cite(reference="bger_6B_267_2012").

I would take (2) for this example, since printing citation strings is what it advertises, and it doubles as a demonstration of the R1 contract (copy citation_string verbatim, never construct it). Which tools return text and which return JSON is genuinely under-documented — that is #73, and your PR is a good argument for prioritising it.

Happy to merge once it prints something. No rush.

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.

Add a minimal Python MCP example

2 participants