You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm building a MCP server using Google as my OAuth Provider (e.g to read mails). Ideally, I would like to mount it on an existing FastAPI server.
importosfromfastapiimportFastAPIfromfastmcpimportFastMCP, Contextfromfastmcp.server.auth.providers.googleimportGoogleProviderfromfastmcp.server.dependenciesimportget_access_tokenfromdotenvimportload_dotenvload_dotenv()
auth=GoogleProvider(
client_id=os.getenv("GOOGLE_CLIENT_ID"),
client_secret=os.getenv("GOOGLE_CLIENT_SECRET"),
base_url="http://localhost:8000",
required_scopes=[
"openid",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/gmail.readonly",
],
)
mcp=FastMCP(name="Gmail MCP Server", auth=auth)
@mcp.toolasyncdefget_user_info() ->dict:
"""Returns information about the authenticated Google user."""fromfastmcp.server.dependenciesimportget_access_tokentoken=get_access_token()
# The GoogleProvider stores user data in token claimsreturn {
"google_id": token.claims.get("sub"),
"email": token.claims.get("email"),
"name": token.claims.get("name"),
"picture": token.claims.get("picture"),
"locale": token.claims.get("locale")
}
mcp_app=mcp.http_app(path='/mcp')
app=FastAPI(title="Gmail MCP Server", lifespan=mcp_app.lifespan)
app.mount("/gmail", mcp_app)
I know the problem is not from fastmcp, but rather from the MCP specification for endpoint discovery. But when mounting an OAuth protected server on a subroute, OAuth endpoints are not properly targeted (e.g putting the "/gmail/mcp" at the end of the well-known endpoints). I don't know why the clients do not try the resource URL from which "/mcp" is removed? Or am I missing something?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm building a MCP server using Google as my OAuth Provider (e.g to read mails). Ideally, I would like to mount it on an existing FastAPI server.
I know the problem is not from fastmcp, but rather from the MCP specification for endpoint discovery. But when mounting an OAuth protected server on a subroute, OAuth endpoints are not properly targeted (e.g putting the "/gmail/mcp" at the end of the well-known endpoints). I don't know why the clients do not try the resource URL from which "/mcp" is removed? Or am I missing something?
Beta Was this translation helpful? Give feedback.
All reactions