This tutorial demonstrates building an HTTP-streamable MCP server that integrates with the Unique SDK to provide search functionality, with a focus on demonstrating how unique credentials (user_id and company_id) can be passed and used by underlying tools for authenticated operations via the Unique SDK. It includes:
Extracting unique credentials (user_id and company_id) from authenticated tokens
A search tool that queries a knowledge base using the Unique SDK with user-specific credentials
An identify tool that retrieves the current user's profile (including user_id and company_id)
Integration with Unique SDK for authenticated search operations using extracted credentials
Note: For fundamental concepts about authentication, server setup, CORS, and deployment, see MCP Fundamentals.
This section provides code snippets for the search-specific implementation. For setup details on authentication, CORS, and server configuration, refer to MCP Fundamentals.
This implementation demonstrates how to extract unique credentials from authenticated tokens. It uses Zitadel's /oidc/v1/userinfo endpoint and extracts company_id from custom claims:
importjson,requestsfromfastmcp.server.dependenciesimportget_access_tokendefget_user():token=get_access_token()iftokenisnotNone:headers={"Authorization":f"Bearer {token.token}"}response=requests.get(f"{ZITADEL_URL}/oidc/v1/userinfo",headers=headers)zitadel_user_info=response.json()user={"email":zitadel_user_info.get("email"),"user_id":zitadel_user_info.get("sub"),"name":zitadel_user_info.get("name"),"company_id":zitadel_user_info.get("urn:zitadel:iam:user:resourceowner:id"),}returnuser@mcp.tooldefidentify(user_prompt:str)->str:"""Identify the user"""user=get_user()returnjson.dumps(user)
@mcp.tooldefsearch(query:str)->str:"""Search in the knowledge base"""user=get_user()# Pass user_id and company_id to Unique SDK for authenticated operationsresult=unique_sdk.Search.create(user_id=user.get("user_id"),company_id=user.get("company_id"),searchString=query,searchType="COMBINED",)returnjson.dumps(result)