Skip to content

Polish simple mcp server#417

Open
amylin1249 wants to merge 6 commits into
mainfrom
polish-simple-mcp-server
Open

Polish simple mcp server#417
amylin1249 wants to merge 6 commits into
mainfrom
polish-simple-mcp-server

Conversation

@amylin1249

@amylin1249 amylin1249 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #416 (can be reviewed commit by commit)

  • Rewrote title, description, and README and updated app screenshot in README
  • Replaced the third-party fastmcp package with the official MCP Python SDK (mcp), clearing all known package vulnerabilities (two critical) and roughly halving the dependency tree
  • Fixed the auth docs: connect_whoami resolves the viewer from the injected session token, not API-key auth; removed the unused x-mcp-authorization header
  • Made failures visible instead of silent or misleading
  • Regenerated requirements.txt from Python 3.11 (was exported for 3.14) and relaxed pins so fastapi/starlette resolve to patched releases; cleaned up pyproject.toml
  • Rewrote instructions on the landing page

Most notable change: the landing page greets the signed-in viewer by name, a live demo of viewer-identity auth. Before you add a "Connect Visitor API Key" integration it tells you to; once added, the same box confirms success by showing your name (or username).

Tested by manually deploying the app.

@github-actions

Copy link
Copy Markdown
Contributor

Extension release summary

🚀 Will release on merge

  • simple-mcp-server: 0.0.60.0.7

See the contributing guide for details.

@amylin1249 amylin1249 force-pushed the polish-simple-mcp-server branch 2 times, most recently from d3bd60a to 595ffbf Compare June 30, 2026 18:37
@amylin1249 amylin1249 marked this pull request as ready for review June 30, 2026 19:21
@amylin1249 amylin1249 marked this pull request as draft July 1, 2026 18:50
@amylin1249 amylin1249 marked this pull request as ready for review July 10, 2026 16:13
@amylin1249 amylin1249 requested review from dotNomad, karawoo and m-- July 10, 2026 16:13
@amylin1249 amylin1249 force-pushed the polish-simple-mcp-server branch from 11e4a0c to 2a5abe2 Compare July 10, 2026 16:31
@amylin1249 amylin1249 force-pushed the polish-simple-mcp-server branch 2 times, most recently from 6bd51fb to 779eebe Compare July 13, 2026 16:33
mcp_app = mcp.http_app(path="/mcp", stateless_http=True)
app = FastAPI(title="Simple MCP Server with FastAPI", lifespan=mcp_app.lifespan)
app = FastAPI(title="MCP Server", lifespan=lifespan)
templates = Jinja2Templates(directory=".")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
templates = Jinja2Templates(directory=".")
templates = Jinja2Templates(directory=".", autoescape=True)

I believe the new starlette version we're using has different behavior that no longer forces autoescape so we should add it explicitly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 2653ff6 - I set templates.env.autoescape = True in a separate line since the suggestion (although it had the right intent) raised a TypeError.

Comment thread extensions/simple-mcp-server/main.py Outdated
session_token = request.headers.get("posit-connect-user-session-token")
if session_token:
try:
me = get_visitor_client(session_token).me

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

get_visitor_client() and .me are blocking HTTP calls but this handler is async, so they run on the event loop. While the event loop is blocked the process can't serve anything else, including MCP tool calls. Same problem in connect_whoami (line 107). I think to fix this we can make get_index_page a plain def (FastAPI will run it in a worker thread), and wrap the posit-sdk calls in connect_whoami in anyio.to_thread.run_sync. The cache will then be shared across threads and needs a lock: @cached(client_cache, lock=threading.Lock()).

@amylin1249 amylin1249 Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I moved the Connect calls in connect_whoami onto a background thread, and added the lock to the cache. But for get_index_page, I didn't make it a def because it has to stay async. It calls get_tools_info() (async), so I moved its blocking Connect call onto a thread instead. get_tools_info is async because it uses the official SDK's mcp.list_tools(), which we adopted when we replaced fastmcp to clear its package vulnerabilities (a lot was surfaced when I ran the package-vulnerability-scanner).

Comment thread extensions/simple-mcp-server/main.py Outdated
"index.html.jinja",
{
"server_name": mcp.name,
"title": "MCP Server",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

just curious why we switched to hardcoding the name here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was my mistake, I think when I tried to make sure the app itself didn't include "FastAPI: " I hardcoded in two spots. Both should be reverted in the most recent commit.

@amylin1249 amylin1249 requested a review from karawoo July 14, 2026 15:43
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.

Polish simple-mcp-server

2 participants