polarity_whoami
Return the polarity user ID and cosmos account info bound to this MCP key. Use it as a connectivity test to identify the user.
Instructions
Returns the polarity user id and cosmos account info that this MCP key is bound to. Cheap connectivity test. Call this first if the user asks who you know them as.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/index.ts:14-19 (handler)The handler for polarity_whoami calls client.whoami(). It's an async function that ignores input and delegates to the CosmosClient's whoami method.
{ name: "polarity_whoami", description: "Returns the polarity user id and cosmos account info that this MCP key is bound to. Cheap connectivity test. Call this first if the user asks who you know them as.", inputSchema: z.object({}).strict(), handler: async (_input, client) => client.whoami(), - src/tools/index.ts:18-18 (schema)The input schema for polarity_whoami is an empty strict Zod object (no arguments required).
inputSchema: z.object({}).strict(), - src/server.ts:38-44 (registration)Tools are registered via the MCP ListToolsRequestSchema handler which maps over the TOOLS array to expose them to clients.
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS.map((t) => ({ name: t.name, description: t.description, inputSchema: zodToJsonSchema(t.inputSchema), })), })); - src/server.ts:46-88 (registration)When a tool call is received (CallToolRequestSchema), the server looks up the tool by name via findTool() and invokes its handler with the parsed input and the CosmosClient.
server.setRequestHandler(CallToolRequestSchema, async (req) => { if (!client) { return { isError: true, content: [{ type: "text", text: UNCONFIGURED_MESSAGE }], }; } const tool = findTool(req.params.name); if (!tool) { return { isError: true, content: [{ type: "text", text: `Unknown tool: ${req.params.name}` }], }; } const parsed = tool.inputSchema.safeParse(req.params.arguments ?? {}); if (!parsed.success) { return { isError: true, content: [ { type: "text", text: `Invalid arguments for ${tool.name}: ${parsed.error.message}`, }, ], }; } try { const result = await tool.handler(parsed.data, client); return { content: [ { type: "text", text: typeof result === "string" ? result : JSON.stringify(result, null, 2) }, ], }; } catch (e) { const message = e instanceof CosmosError ? `${e.status} from cosmos at ${e.path}: ${typeof e.body === "string" ? e.body : JSON.stringify(e.body)}` : e instanceof Error ? e.message : String(e); return { isError: true, content: [{ type: "text", text: message }] }; } }); - src/tools/index.ts:166-168 (helper)findTool() is a helper that looks up a ToolDef by name from the TOOLS array. Used by the MCP server to dispatch tool calls.
export function findTool(name: string): ToolDef | undefined { return TOOLS.find((t) => t.name === name); } - src/client/cosmos.ts:155-161 (helper)The whoami() method on CosmosClient makes a GET request to /api/polarity/whoami and returns a WhoamiResponse (polarity_user_id, cosmos_user_id, scopes, created_at).
whoami() { return this.request<WhoamiResponse>({ method: "GET", path: "/api/polarity/whoami", }); } }