discourse_get_user
Retrieve basic user information from Discourse forums by providing a username. This tool enables AI agents to access user profiles for forum interaction and data retrieval.
Instructions
Get basic user info.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes |
Implementation Reference
- src/tools/builtin/get_user.ts:16-37 (handler)The tool handler that executes the logic to fetch user data from Discourse API, process it, and return formatted text or error.async ({ username }, _extra: any) => { try { const { base, client } = ctx.siteState.ensureSelectedSite(); const data = (await client.get(`/u/${encodeURIComponent(username)}.json`)) as any; const user = data?.user || data?.user_badges || data; const name = user?.name || username; const trust = user?.trust_level; const created = user?.created_at || user?.user?.created_at || ""; const bio = user?.bio_raw || ""; const lines = [ `@${username} (${name})`, trust != null ? `Trust level: ${trust}` : undefined, created ? `Joined: ${created}` : undefined, bio ? "" : undefined, bio ? bio.slice(0, 1000) : undefined, `Profile: ${base}/u/${encodeURIComponent(username)}`, ].filter(Boolean) as string[]; return { content: [{ type: "text", text: lines.join("\n") }] }; } catch (e: any) { return { content: [{ type: "text", text: `Failed to get user ${username}: ${e?.message || String(e)}` }], isError: true }; } }
- src/tools/builtin/get_user.ts:5-7 (schema)Input schema using Zod for validating the 'username' parameter.const schema = z.object({ username: z.string().min(1), });
- src/tools/builtin/get_user.ts:9-38 (registration)Registers the 'discourse_get_user' tool on the MCP server with title, description, input schema, and handler function.server.registerTool( "discourse_get_user", { title: "Get User", description: "Get basic user info.", inputSchema: schema.shape, }, async ({ username }, _extra: any) => { try { const { base, client } = ctx.siteState.ensureSelectedSite(); const data = (await client.get(`/u/${encodeURIComponent(username)}.json`)) as any; const user = data?.user || data?.user_badges || data; const name = user?.name || username; const trust = user?.trust_level; const created = user?.created_at || user?.user?.created_at || ""; const bio = user?.bio_raw || ""; const lines = [ `@${username} (${name})`, trust != null ? `Trust level: ${trust}` : undefined, created ? `Joined: ${created}` : undefined, bio ? "" : undefined, bio ? bio.slice(0, 1000) : undefined, `Profile: ${base}/u/${encodeURIComponent(username)}`, ].filter(Boolean) as string[]; return { content: [{ type: "text", text: lines.join("\n") }] }; } catch (e: any) { return { content: [{ type: "text", text: `Failed to get user ${username}: ${e?.message || String(e)}` }], isError: true }; } } );
- src/tools/registry.ts:55-55 (registration)Top-level call to the registerGetUser function within the registerAllTools to include the tool.registerGetUser(server, ctx, { allowWrites: false });