Skip to content

Conversation

@speterkins
Copy link
Contributor

@speterkins speterkins commented Oct 27, 2025

FastMCP Integration

This PR introduces FastMCP integration into the repository, enabling lightweight middleware to capture North-specific context without enabling full authentication.

Key Changes:

  • New Middleware: The FastMCPNorthMiddleware class is introduced in src/north_mcp_python_sdk/middleware.py. This middleware extracts North request metadata from headers, specifically the X-North-User-ID-Token and X-North-Connector-Tokens headers.
  • Context Handling: The middleware uses a NorthRequestContext dataclass to hold the extracted context, which includes the user_id_token and connector_tokens. This context is made available through a contextvars.ContextVar named north_request_context_var.
  • Utility Functions: The get_north_request_context function is provided to retrieve the North request context for the current request.
  • Logging: The middleware includes debug logging to help with troubleshooting.
  • Documentation: The README.md file is updated to include an example of how to use the new middleware with FastMCP.
  • Exports: The new middleware and related utilities are added to the __all__ list in src/north_mcp_python_sdk/__init__.py, making them part of the public API.

@speterkins speterkins force-pushed the speterkins/fastmcp-north-middleware branch from ccff3fb to 5aaed4c Compare October 28, 2025 18:14
@speterkins speterkins force-pushed the speterkins/fastmcp-north-middleware branch from 5aaed4c to 7135119 Compare October 28, 2025 18:15
Copy link
Collaborator

@raphael-cohere raphael-cohere left a comment

Choose a reason for hiding this comment

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

Love the idea, but some thoughts:
Can we reuse this middleware for the current library that we are using? Ideally we could share this code

@speterkins
Copy link
Contributor Author

@raphael-cohere sharing the helper was the right call. I've made a change to reuse a common parsing/context module so both stacks expose the same request context.

We still keep two middleware layers on purpose:

  • The existing NorthMCP middleware enforces service auth: it verifies headers, returns 401s, and only passes through requests with the expected North auth.
  • The lightweight FastMCP middleware just extracts any North headers if they exist and never blocks the request. That lets a generic MCP server work with multiple clients, even when those headers are absent.

If we exposed only the full auth middleware, every FastMCP app would need North headers on every request, which defeats the “generic MCP server” story. This split keeps auth strict where we need it while offering a non-blocking option to broader consumers.

NorthAuthenticationMiddleware and FastMCPNorthMiddleware
@speterkins speterkins force-pushed the speterkins/fastmcp-north-middleware branch from 49e0502 to 0a16a6a Compare October 30, 2025 18:51
@speterkins speterkins marked this pull request as ready for review October 31, 2025 14:15
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.

3 participants