Before you start
You need a Haplotype Wallet account that is past the waitlist. Until then the server accepts your token and every data tool refuses the call. See Errors.
The examples use the endpoint https://api.haplotype.ai/mcp.
If you are building an app that your users connect to their wallet, we issue your credentials and the authorization works differently. Follow Connect Wallet for that part, then come back here for the calls.
Authorize
The server is an OAuth 2.1 resource server. It accepts a bearer token that our authorization server issued for this endpoint, and nothing else. There are no API keys.
An MCP client gets that token in five steps. Nothing is configured by hand, because each step tells the client where the next one is.
GET https://api.haplotype.ai/.well-known/oauth-protected-resource/mcpreturns theresourceidentifier and theauthorization_serverslist.GET <authorization server>/.well-known/oauth-authorization-serverreturns the authorization, token and registration endpoints.POSTto the registration endpoint registers your client (dynamic client registration, RFC 7591). A public client sends"token_endpoint_auth_method": "none".- Send the user to the authorization endpoint with a PKCE challenge (
S256) andresourceset to the value from step 1. They sign in and come back to your redirect URI with a code. POSTthe code and the PKCE verifier to the token endpoint, with the sameresource.
Step 4 is where hand-written clients go wrong. The resource parameter
(RFC 8707) is what puts this endpoint in the token's audience. Leave it out and
you get a valid-looking token that the server rejects with 401.
You rarely need to write this yourself. Both SDKs below run the whole flow if
you give them a place to store tokens and a way to open a browser. In
TypeScript that is the authProvider option of StreamableHTTPClientTransport.
In Python it is OAuthClientProvider from mcp.client.auth.
The examples below take an access token as given, so the MCP calls stay in view.
Connect and call
Both examples connect, list the tools, and call
lookup_variant_references,
which reads public reference data and needs no uploaded sample.
Python
Install the official SDK with pip install mcp.
import asyncio
import httpx
from mcp import ClientSession
from mcp.client.streamable_http import streamable_http_client
MCP_URL = "https://api.haplotype.ai/mcp"
async def main(access_token: str) -> None:
headers = {"Authorization": f"Bearer {access_token}"}
# httpx gives up after 5 seconds by default. A tool call can take longer.
timeout = httpx.Timeout(30, read=300)
async with (
httpx.AsyncClient(headers=headers, timeout=timeout) as http,
streamable_http_client(MCP_URL, http_client=http) as (read, write, _),
ClientSession(read, write) as session,
):
await session.initialize()
tools = await session.list_tools()
print([tool.name for tool in tools.tools])
result = await session.call_tool(
"lookup_variant_references", {"rs_ids": ["rs429358", "rs7412"]}
)
if result.isError:
raise RuntimeError(result.content[0].text)
print(result.structuredContent)
asyncio.run(main("<access token>"))
TypeScript
Install the official SDK with pnpm add @modelcontextprotocol/sdk.
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
const MCP_URL = "https://api.haplotype.ai/mcp";
const accessToken = "<access token>";
const transport = new StreamableHTTPClientTransport(new URL(MCP_URL), {
requestInit: { headers: { Authorization: `Bearer ${accessToken}` } },
});
const client = new Client({ name: "my-app", version: "1.0.0" });
await client.connect(transport);
const { tools } = await client.listTools();
console.log(tools.map((tool) => tool.name));
const result = await client.callTool({
name: "lookup_variant_references",
arguments: { rs_ids: ["rs429358", "rs7412"] },
});
if (result.isError) throw new Error(JSON.stringify(result.content));
console.log(result.structuredContent);
await client.close();
Plain HTTP
MCP over Streamable HTTP is JSON-RPC 2.0 in POST bodies. The server is
stateless: there is no session to open and no initialize call to make first.
Each request stands on its own.
List the tools with "method":"tools/list", or call one.
curl https://api.haplotype.ai/mcp \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"lookup_variant_references","arguments":{"rs_ids":["rs429358","rs7412"]}}}'
The Accept header must list both types, or the server answers 406.
Responses arrive as a server-sent event. The JSON-RPC message is on the data:
line.
event: message
data: {"jsonrpc":"2.0","id":2,"result":{"content":[...],"structuredContent":{...},"isError":false}}
Reading the result
A tool's return value is in structuredContent. A tool that returns a list
wraps it as {"result": [...]}, because MCP requires an object there. The
tool reference says which tools return a list.
When a call fails, isError is true and the message is the text of the first
content block. The HTTP status is still 200. Errors
covers each case.