Skip to main content
Glama

mastodon_search

Search for accounts, hashtags, or posts on Mastodon using specific queries and filters to find relevant content across the platform.

Instructions

Search for accounts, hashtags, or posts on Mastodon

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query text
typeNoType of content to search for
limitNoNumber of results to return (1-40)
resolveNoWhether to resolve non-local accounts/statuses
followingNoOnly search accounts the user is following

Implementation Reference

  • Handler function that executes the mastodon_search tool: formats search parameters, calls MastodonClient.search, processes results into sections for accounts, hashtags, statuses, and returns formatted text content.
    async (params: SearchParams) => {
      const searchParams = {
        q: params.query,
        type: params.type,
        limit: params.limit,
        resolve: params.resolve,
        following: params.following,
      };
    
      const results = await client.search(searchParams);
      
      const sections = [];
      
      if (results.accounts.length > 0) {
        const accountsList = results.accounts.map((account, index) => {
          return `${index + 1}. @${account.acct} (${account.display_name})\n   Followers: ${account.followers_count} | Following: ${account.following_count} | Posts: ${account.statuses_count}\n   ${account.note.replace(/<[^>]*>/g, '').substring(0, 100)}...\n   URL: ${account.url}`;
        }).join('\n\n');
        sections.push(`**Accounts (${results.accounts.length})**\n${accountsList}`);
      }
      
      if (results.hashtags.length > 0) {
        const hashtagsList = results.hashtags.map((tag, index) => {
          const todayHistory = tag.history[0];
          const uses = todayHistory ? `${todayHistory.uses} uses` : "No recent data";
          return `${index + 1}. #${tag.name} (${uses})\n   URL: ${tag.url}`;
        }).join('\n\n');
        sections.push(`**Hashtags (${results.hashtags.length})**\n${hashtagsList}`);
      }
      
      if (results.statuses.length > 0) {
        const statusesList = results.statuses.map((post, index) => {
          const mediaInfo = post.media_attachments.length > 0 ? ` [${post.media_attachments.length} media]` : "";
          return `${index + 1}. @${post.account.acct}: ${post.content.replace(/<[^>]*>/g, '').substring(0, 100)}...${mediaInfo}\n   Posted: ${new Date(post.created_at).toLocaleString()}\n   URL: ${post.url}`;
        }).join('\n\n');
        sections.push(`**Posts (${results.statuses.length})**\n${statusesList}`);
      }
      
      if (sections.length === 0) {
        return {
          content: [
            {
              type: "text",
              text: `No results found for query: "${params.query}"`
            }
          ],
        };
      }
      
      const summary = `Search results for "${params.query}"`;
      return {
        content: [
          {
            type: "text",
            text: `${summary}\n\n${sections.join('\n\n')}`,
          },
        ],
      };
    }
  • Zod input schema (SearchSchema) defining parameters for the mastodon_search tool: query, type, limit, resolve, following.
    const SearchSchema = z.object({
      query: z.string().describe("Search query text"),
      type: z
        .enum(["accounts", "hashtags", "statuses"])
        .describe("Type of content to search for")
        .optional(),
      limit: z
        .number()
        .min(1)
        .max(40)
        .describe("Number of results to return (1-40)")
        .default(20)
        .optional(),
      resolve: z
        .boolean()
        .describe("Whether to resolve non-local accounts/statuses")
        .default(false)
        .optional(),
      following: z
        .boolean()
        .describe("Only search accounts the user is following")
        .default(false)
        .optional(),
    });
  • Registration of the mastodon_search tool on the MCP server using server.tool, providing name, description, input schema, and handler function.
    server.tool(
      "mastodon_search",
      "Search for accounts, hashtags, or posts on Mastodon",
      SearchSchema.shape,
      async (params: SearchParams) => {
        const searchParams = {
          q: params.query,
          type: params.type,
          limit: params.limit,
          resolve: params.resolve,
          following: params.following,
        };
    
        const results = await client.search(searchParams);
        
        const sections = [];
        
        if (results.accounts.length > 0) {
          const accountsList = results.accounts.map((account, index) => {
            return `${index + 1}. @${account.acct} (${account.display_name})\n   Followers: ${account.followers_count} | Following: ${account.following_count} | Posts: ${account.statuses_count}\n   ${account.note.replace(/<[^>]*>/g, '').substring(0, 100)}...\n   URL: ${account.url}`;
          }).join('\n\n');
          sections.push(`**Accounts (${results.accounts.length})**\n${accountsList}`);
        }
        
        if (results.hashtags.length > 0) {
          const hashtagsList = results.hashtags.map((tag, index) => {
            const todayHistory = tag.history[0];
            const uses = todayHistory ? `${todayHistory.uses} uses` : "No recent data";
            return `${index + 1}. #${tag.name} (${uses})\n   URL: ${tag.url}`;
          }).join('\n\n');
          sections.push(`**Hashtags (${results.hashtags.length})**\n${hashtagsList}`);
        }
        
        if (results.statuses.length > 0) {
          const statusesList = results.statuses.map((post, index) => {
            const mediaInfo = post.media_attachments.length > 0 ? ` [${post.media_attachments.length} media]` : "";
            return `${index + 1}. @${post.account.acct}: ${post.content.replace(/<[^>]*>/g, '').substring(0, 100)}...${mediaInfo}\n   Posted: ${new Date(post.created_at).toLocaleString()}\n   URL: ${post.url}`;
          }).join('\n\n');
          sections.push(`**Posts (${results.statuses.length})**\n${statusesList}`);
        }
        
        if (sections.length === 0) {
          return {
            content: [
              {
                type: "text",
                text: `No results found for query: "${params.query}"`
              }
            ],
          };
        }
        
        const summary = `Search results for "${params.query}"`;
        return {
          content: [
            {
              type: "text",
              text: `${summary}\n\n${sections.join('\n\n')}`,
            },
          ],
        };
      }
    );
  • MastodonClient.search helper method called by the tool handler to perform the actual API search request.
    async search(params: SearchParams): Promise<MastodonSearchResults> {
      const queryParams = this.buildQueryParams(params);
      return this.request<MastodonSearchResults>(`/api/v2/search${queryParams}`);
    }
  • TypeScript interface defining the structure of search results returned by Mastodon API (used by client.search).
    export interface MastodonSearchResults {
      accounts: MastodonAccount[];
      statuses: MastodonStatus[];
      hashtags: MastodonTrendingTag[];
    }
  • Top-level call to addMastodonTool which registers all Mastodon tools including mastodon_search.
    // Add Mastodon tool to server
    await addMastodonTool(server);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure but only states the basic action without details on permissions, rate limits, pagination, or response format. It doesn't mention whether this is a read-only operation, what authentication is required, or how results are structured, which are critical for a search tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It is front-loaded and wastes no space, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a search tool with 5 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain return values, error conditions, or behavioral nuances, leaving significant gaps for the agent to operate effectively in this context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds no parameter-specific information beyond what the input schema already provides, as schema description coverage is 100%. The schema fully documents all parameters (query, type, limit, resolve, following) with descriptions, enums, defaults, and constraints, so the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Search') and resource ('accounts, hashtags, or posts on Mastodon'), making the purpose immediately understandable. However, it doesn't explicitly differentiate this search tool from sibling tools like 'mastodon_get_timeline' or 'mastodon_get_trending_tags', which also retrieve content but with different approaches.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'mastodon_get_trending_tags' for hashtag discovery or 'mastodon_get_timeline' for chronological posts. It lacks context about use cases, prerequisites, or exclusions, leaving the agent to infer usage from the tool name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/The-Focus-AI/mastodon-mcp'

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