discourse_select_site
Validate and select a Discourse site URL to enable AI agents to interact with forum content through search, reading, and posting operations.
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)The main handler function that executes the tool: validates the site URL by fetching /about.json, selects the site in state, attempts remote tool registration if enabled, and returns a success or error message.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)Zod schema defining the input parameter 'site' as a URL string.const schema = z.object({ site: z.string().url().describe("Base URL of the Discourse site"), });
- src/tools/builtin/select_site.ts:10-36 (registration)Direct registration of the 'discourse_select_site' tool including name, metadata, 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:47-48 (registration)Top-level registration call to registerSelectSite from the main registry function, conditional on not hiding the select site tool.if (!opts.hideSelectSite) { registerSelectSite(server, ctx, { allowWrites: false, toolsMode: opts.toolsMode });
- src/tools/registry.ts:13-13 (registration)Import of the registerSelectSite function used to register the tool.import { registerSelectSite } from "./builtin/select_site.js";