Skip to main content
Glama

discourse_select_site

Validate and select a Discourse site URL to enable subsequent interactions with forum content through search, reading, and management tools.

Instructions

Validate and select a Discourse site for subsequent tool calls.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
siteYesBase URL of the Discourse site

Implementation Reference

  • The main handler function for the 'discourse_select_site' tool. It validates the provided site URL by fetching /about.json, selects the site in the state, optionally registers remote tools, and returns a confirmation message 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 }; } }
  • Zod schema defining the input for the tool: a required 'site' parameter that must be a valid URL.
    const schema = z.object({ site: z.string().url().describe("Base URL of the Discourse site"), });
  • The registerSelectSite function that defines and registers the 'discourse_select_site' tool with the MCP server, including schema, metadata, and handler.
    export const registerSelectSite: RegisterFn = (server, ctx, opts) => { const schema = z.object({ site: z.string().url().describe("Base URL of the Discourse site"), }); 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 }; } } ); };
  • Invocation of registerSelectSite during the overall tool registration process in registerAllTools, conditionally skipping if hideSelectSite is true.
    if (!opts.hideSelectSite) { registerSelectSite(server, ctx, { allowWrites: false, toolsMode: opts.toolsMode }); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/discourse/discourse-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server