discourse_select_site
Validate and select a Discourse site URL for AI agents to perform actions like reading posts, browsing categories, and creating content via the Discourse MCP server.
Instructions
Validate and select a Discourse site for subsequent tool calls.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| site | Yes | Base URL of the Discourse site |
Implementation Reference
- src/tools/builtin/select_site.ts:17-35 (handler)Executes the discourse_select_site tool: validates Discourse site URL by fetching /about.json, selects the site in state, optionally registers remote tools, returns confirmation or error.async ({ site }, _extra: any) => { try { const { base, client } = ctx.siteState.buildClientForSite(site); // Validate by fetching /about.json const about = (await client.get(`/about.json`)) as any; const title = about?.about?.title || about?.title || base; ctx.siteState.selectSite(base); // Attempt remote tool discovery if enabled if (opts.toolsMode && opts.toolsMode !== "discourse_api_only") { await tryRegisterRemoteTools(server, ctx.siteState, ctx.logger); } const text = `Selected site: ${base}\nTitle: ${title}`; return { content: [{ type: "text", text }] }; } catch (e: any) { return { content: [{ type: "text", text: `Failed to select site: ${e?.message || String(e)}` }], isError: true }; } }
- src/tools/builtin/select_site.ts:6-8 (schema)Input schema using Zod: requires 'site' as a valid URL.const schema = z.object({ site: z.string().url().describe("Base URL of the Discourse site"), });
- src/tools/builtin/select_site.ts:10-36 (registration)Registers the 'discourse_select_site' tool with title, description, input schema, and handler function.server.registerTool( "discourse_select_site", { title: "Select Site", description: "Validate and select a Discourse site for subsequent tool calls.", inputSchema: schema.shape, }, async ({ site }, _extra: any) => { try { const { base, client } = ctx.siteState.buildClientForSite(site); // Validate by fetching /about.json const about = (await client.get(`/about.json`)) as any; const title = about?.about?.title || about?.title || base; ctx.siteState.selectSite(base); // Attempt remote tool discovery if enabled if (opts.toolsMode && opts.toolsMode !== "discourse_api_only") { await tryRegisterRemoteTools(server, ctx.siteState, ctx.logger); } const text = `Selected site: ${base}\nTitle: ${title}`; return { content: [{ type: "text", text }] }; } catch (e: any) { return { content: [{ type: "text", text: `Failed to select site: ${e?.message || String(e)}` }], isError: true }; } } );
- src/tools/registry.ts:38-40 (registration)Conditionally registers the select_site tool as part of the overall tool registration process.if (!opts.hideSelectSite) { registerSelectSite(server, ctx, { allowWrites: false, toolsMode: opts.toolsMode }); }