Skip to main content
Glama
xraywu

Wegene Assistant MCP Server

by xraywu

wegene-oauth

Authorize user accounts via WeGene Open API using OAuth2, retrieve access tokens, and enable secure access to genetic testing report data for further API utilization.

Instructions

Authorizing a user's account using WeGene Open API with oAuth2 protocol and retrieve a valid access token for further use

Input Schema

NameRequiredDescriptionDefault

No arguments

Input Schema (JSON Schema)

{ "properties": {}, "type": "object" }

Implementation Reference

  • The core handler function for the 'wegene-oauth' tool. It deletes any existing token, opens a browser for WeGene OAuth authorization, and polls Redis for up to 120 seconds for the access token set by the callback Flask server.
    async def wegene_oauth(): redis_db.delete('wegene_access_token') # Initialize OAuth2 client client = WebApplicationClient(WEGENE_CLIENT_ID) # Prepare authorization URL authorization_url = client.prepare_request_uri( WEGENE_AUTH_URL, redirect_uri=REDIRECT_URI, scope="basic names athletigen skin psychology risk health" ) webbrowser.open(authorization_url) # Poll for access token for 120 seconds start_time = time.time() while time.time() - start_time < 120: if redis_db.exists('wegene_access_token'): return [ TextContent( type="text", text="User authorization succeeded and access token retrieved. Continue to retrieve user profiles.", ) ] await asyncio.sleep(1) return [ TextContent( type="text", text="Error: User authorization failed in 120 seconds. Please try again." ) ]
  • The tool is registered in handle_list_tools() with name, description, and empty inputSchema. It is dispatched in handle_call_tool() by checking the name and calling the imported wegene_oauth() function.
    @server.list_tools() async def handle_list_tools() -> list[types.Tool]: """ A user can have multiple "profiles(检测报告)" under his/her WeGene account. Each profile(检测报告)represeting the results of a person's single genetic test, consists of multiple reports(检测结果) for difference phenotypes. First, use wegene-oauth tool to authorize the user's account and set a valid access token for further use. Then, use wegene-get-profiles tool to retrieve the list of profiles under this user's account. Resource list will be updated according to all the profiles. Then, get the report info from wegene-get-report-info tool to retrieve the report IDs and categories. Finally, use wegene-get-report tool to retrieve the testing results from a profile. """ return [ types.Tool( name="wegene-oauth", description="Authorizing a user's account using WeGene Open API with oAuth2 protocol and retrieve a valid access token for further use", inputSchema={ "type": "object", "properties": {}, }, ), types.Tool( name="wegene-get-profiles", description="Retrieve all the profiles under the current account", inputSchema={ "type": "object", "properties": {} }, ), types.Tool( name="wegene-get-report-info", description="Get all available report information", inputSchema={ "type": "object", "properties": {} }, ), types.Tool( name="wegene-get-report", description="Get a specific genetic test report from a profile", inputSchema={ "type": "object", "properties": { "report_endpoint": { "type": "string", "description": "The endpoint of the report" }, "report_id": { "type": "string", "description": "The ID of the report" }, "profile_id": { "type": "string", "description": "The ID of the profile" } }, "required": ["report_endpoint", "report_id", "profile_id"] }, ) ] @server.call_tool() async def handle_call_tool( name: str, arguments: dict | None ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]: """ Tools to retrieve genetic testing reports from WeGene. wegene-oauth: Start an OAuth Web procress and retireve the access token for further use. The tool will wait for 120 seconds for the user to complete the authorization process. If not completed, the tool will fail. wegene-get-profiles: Get all the profiles under the user's account and build resources accordingly. wegene-get-report-info: Get all the report information and metadata, including report ID, cegtagory, name, etc. wegene-get-report: Get the genetic testing report for a specific phenotype from a profile. Result return in JSON format. Example result format: ```json { "score" : 60, # 0-100, relative score among the population for athletigen, skin, psychology, metabolism "genotypes" : [ # The list of the user's SNPs related to this phenotype report { "tsummary" : "抗晒黑能力中等", # Effect of this SNP's genotype "genotype" : "CT", # Genotype of the SNP "rsid" : "RS1015362" # SNP RSID }, { "genotype" : "CC", "tsummary" : "抗晒黑能力弱", "gene" : "IRF4", "rsid" : "RS12203592" } ], "description" : "抗晒黑反应能力", # The report name "tsummary" : "喝酒不脸红", # The overall result for drug, traits, "rank" : "强", # The overall result for athletigen, skin, psychology, metabolism "risk": 0.31 # The overall result for health risk, the relative risk comparing to the average population "caseid" : "1522" # The report ID } ``` """ if name == "wegene-oauth": return await wegene_oauth()
  • The input schema for the 'wegene-oauth' tool, which takes no parameters (empty properties).
    types.Tool( name="wegene-oauth", description="Authorizing a user's account using WeGene Open API with oAuth2 protocol and retrieve a valid access token for further use", inputSchema={ "type": "object", "properties": {}, }, ),
  • OAuth configuration constants used by the handler, loaded from environment variables.
    # WeGene OAuth configuration WEGENE_CLIENT_ID = os.getenv('WEGENE_CLIENT_ID') WEGENE_CLIENT_SECRET = os.getenv('WEGENE_CLIENT_SECRET') WEGENE_AUTH_URL = "https://api.wegene.com/authorize/" REDIRECT_URI = "http://localhost:8787/oauth/callback"
  • Import of the wegene_oauth handler function into the server for use in tool dispatch.
    from .tools.oauth_tool import wegene_oauth

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/xraywu/mcp-wegene-assistant'

If you have feedback or need assistance with the MCP directory API, please join our Discord server