Skip to content

Commit a47d6ca

Browse files
authored
Merge pull request #34 from IBM/new-roadmap
fixed linting for examples
2 parents 8b7fabe + b36bd32 commit a47d6ca

4 files changed

Lines changed: 190 additions & 0 deletions

File tree

examples/chuk_decorator_server.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
Shot 5: The Decorator Version — the payoff.
3+
4+
Same language popularity data, but using @chart_tool from chuk-view-schemas.
5+
No HTML. No JavaScript. No resource registration. No CallToolResult boilerplate.
6+
7+
This is the chuk-mcp-server equivalent of decorator_server.py.
8+
The only difference from the FastMCP version is the import path:
9+
FastMCP: from chuk_view_schemas.fastmcp import chart_tool
10+
ChukMCPServer: from chuk_view_schemas.chuk_mcp import chart_tool
11+
12+
Run locally: uv run examples/chuk_decorator_server.py
13+
"""
14+
15+
from chuk_view_schemas.chart import ChartContent, ChartDataset
16+
from chuk_view_schemas.chuk_mcp import chart_tool
17+
18+
from chuk_mcp_server import ChukMCPServer
19+
20+
mcp = ChukMCPServer(
21+
name="language-stats",
22+
version="1.0.0",
23+
description="Decorator-based MCP Apps demo",
24+
)
25+
26+
27+
@chart_tool(mcp, "show_popularity")
28+
async def show_popularity(chart_type: str = "bar") -> ChartContent:
29+
"""Show programming language popularity as an interactive chart.
30+
chart_type: bar, pie, line, doughnut, or area."""
31+
return ChartContent(
32+
chartType=chart_type,
33+
title="Programming Language Popularity (2026)",
34+
data=[
35+
ChartDataset(
36+
label="Usage %",
37+
values=[
38+
{"label": "Python", "value": 31.0},
39+
{"label": "JavaScript", "value": 25.2},
40+
{"label": "Rust", "value": 18.1},
41+
{"label": "Go", "value": 14.3},
42+
{"label": "TypeScript", "value": 11.4},
43+
],
44+
)
45+
],
46+
)
47+
48+
49+
if __name__ == "__main__":
50+
mcp.run()

examples/chuk_manual_server.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
"""
2+
Shot 4: The @mcp.view_tool() Way — built-in chuk-mcp-server decorator.
3+
4+
One decorator handles all the MCP Apps plumbing:
5+
- Builds _meta.ui with resourceUri and viewUrl
6+
- Sets readOnlyHint=True
7+
- Auto-registers the ui:// resource (fetches HTML from viewUrl CDN)
8+
- Enables the experimental MCP Apps capability
9+
10+
No HTML. No JavaScript. No manual resource registration.
11+
You just return content + structuredContent.
12+
13+
This is the chuk-mcp-server equivalent of manual_server.py.
14+
15+
Run locally: uv run examples/chuk_manual_server.py
16+
"""
17+
18+
from chuk_mcp_server import ChukMCPServer
19+
20+
mcp = ChukMCPServer(
21+
name="language-stats",
22+
version="1.0.0",
23+
description="MCP Apps with @mcp.view_tool()",
24+
)
25+
26+
27+
@mcp.view_tool(
28+
resource_uri="ui://language-stats/chart",
29+
view_url="https://chuk-mcp-ui-views.fly.dev/chart/v1",
30+
description="Show programming language popularity as an interactive chart.",
31+
)
32+
async def show_chart(chart_type: str = "bar") -> dict:
33+
"""Show programming language popularity as an interactive chart.
34+
chart_type: bar, pie, line, doughnut, or area."""
35+
36+
data = {
37+
"Python": 31.0,
38+
"JavaScript": 25.2,
39+
"Rust": 18.1,
40+
"Go": 14.3,
41+
"TypeScript": 11.4,
42+
}
43+
44+
return {
45+
# What the LLM sees — text summary for reasoning
46+
"content": [
47+
{
48+
"type": "text",
49+
"text": f"Programming language popularity ({chart_type} chart).",
50+
}
51+
],
52+
# What the UI sees — full data, hydrates the chart component
53+
"structuredContent": {
54+
"type": "chart",
55+
"version": "1.0",
56+
"title": "Programming Language Popularity (2026)",
57+
"chartType": chart_type,
58+
"data": [
59+
{
60+
"label": "Usage %",
61+
"values": [{"label": lang, "value": pct} for lang, pct in data.items()],
62+
}
63+
],
64+
},
65+
}
66+
67+
68+
if __name__ == "__main__":
69+
mcp.run()

examples/chuk_server.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
MCP Apps Record — three demo servers composed into one.
3+
4+
This is the chuk-mcp-server equivalent of server.py.
5+
6+
Instead of Starlette path mounts, chuk-mcp-server uses import_server()
7+
to compose multiple servers into a single MCP endpoint. Tools get
8+
namespaced with a prefix:
9+
10+
simple.get_language_popularity — Shot 3: plain text, no MCP Apps
11+
manual.show_chart — Shot 4: @mcp.view_tool() decorator
12+
decorator.show_popularity — Shot 5: @chart_tool from chuk-view-schemas
13+
14+
Run locally: uv run examples/chuk_server.py
15+
"""
16+
17+
from chuk_decorator_server import mcp as decorator_mcp
18+
from chuk_manual_server import mcp as manual_mcp
19+
from chuk_simple_server import mcp as simple_mcp
20+
21+
from chuk_mcp_server import ChukMCPServer
22+
23+
app = ChukMCPServer(
24+
name="language-stats-combined",
25+
version="1.0.0",
26+
description="Combined MCP Apps demo — plain, manual, and decorator",
27+
)
28+
29+
# Compose all three servers into one, each with a namespace prefix.
30+
# import_server copies tools (and resources/prompts) at init time.
31+
app.import_server(simple_mcp, prefix="simple")
32+
app.import_server(manual_mcp, prefix="manual")
33+
app.import_server(decorator_mcp, prefix="decorator")
34+
35+
if __name__ == "__main__":
36+
app.run()

examples/chuk_simple_server.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
Shot 3: The "Before" — a plain MCP server with no MCP Apps.
3+
Returns programming language popularity as plain text.
4+
5+
This is the chuk-mcp-server equivalent of simple_server.py.
6+
Same behavior, different framework.
7+
8+
Run locally: uv run examples/chuk_simple_server.py
9+
"""
10+
11+
from chuk_mcp_server import ChukMCPServer
12+
13+
mcp = ChukMCPServer(
14+
name="language-stats",
15+
version="1.0.0",
16+
description="Plain text language popularity stats",
17+
)
18+
19+
20+
@mcp.tool
21+
async def get_language_popularity() -> str:
22+
"""Get programming language popularity from latest survey data."""
23+
data = {
24+
"Python": 31.0,
25+
"JavaScript": 25.2,
26+
"Rust": 18.1,
27+
"Go": 14.3,
28+
"TypeScript": 11.4,
29+
}
30+
lines = [f" {lang}: {pct}%" for lang, pct in data.items()]
31+
return "Programming Language Popularity (2026):\n" + "\n".join(lines)
32+
33+
34+
if __name__ == "__main__":
35+
mcp.run()

0 commit comments

Comments
 (0)