Skip to main content
Glama
matteoantoci

Marketstack MCP Server

by matteoantoci

list_exchanges

Retrieve detailed information on over 2700 stock exchanges by searching name or MIC, with pagination options for managing large datasets efficiently.

Instructions

Look up information any of the 2700+ stock exchanges supported by this endpoint.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoSpecify a pagination limit (number of results per page) for your API request. Default limit value is `100`, maximum allowed limit value is `1000`.
offsetNoSpecify a pagination offset value for your API request. Example: An offset value of `100` combined with a limit value of 10 would show results 100-110. Default value is `0`, starting with the first available result.
searchNoUse this parameter to search stock exchanges by name or MIC.

Implementation Reference

  • The handler function for the 'list_exchanges' tool that fetches exchange data from Marketstack API using provided search, limit, and offset parameters.
    const listExchangesHandler = async (input: Input, client: MarketstackClient): Promise<Output> => {
      try {
        const { search, limit, offset } = input;
    
        const apiRequestParams: MarketstackApiParams = {
          endpoint: 'exchanges',
          ...(search && { search }), // Include if search is provided
          ...(limit && { limit }), // Include if limit is provided
          ...(offset && { offset }), // Include if offset is provided
        };
    
        const data = await client.fetchApiData(apiRequestParams);
    
        return data;
      } catch (error: unknown) {
        console.error('listExchanges tool error:', error);
        const message = error instanceof Error ? error.message : 'An unknown error occurred.';
        throw new Error(`listExchanges tool failed: ${message}`);
      }
    };
  • Zod-based input schema shape for the 'list_exchanges' tool, defining optional search, limit, and offset parameters.
    const listExchangesInputSchemaShape = {
      search: z.string().optional().describe('Use this parameter to search stock exchanges by name or MIC.'),
      limit: z
        .number()
        .int()
        .min(1)
        .max(1000)
        .optional()
        .default(100)
        .describe(
          'Specify a pagination limit (number of results per page) for your API request. Default limit value is `100`, maximum allowed limit value is `1000`.'
        ),
      offset: z
        .number()
        .int()
        .min(0)
        .optional()
        .default(0)
        .describe(
          'Specify a pagination offset value for your API request. Example: An offset value of `100` combined with a limit value of 10 would show results 100-110. Default value is `0`, starting with the first available result.'
        ),
    };
  • Registration of the 'list_exchanges' tool with the MCP server using server.tool(), wrapping the handler for client injection.
    server.tool(
      listExchangesTool.name,
      listExchangesTool.description,
      listExchangesTool.inputSchemaShape,
      wrapToolHandler((input) => listExchangesTool.handler(input, client))
    );
  • Tool definition object exporting name, description, input schema, and handler for the 'list_exchanges' tool.
    export const listExchangesTool: MarketstackToolDefinition = {
      name: 'list_exchanges',
      description: 'Look up information any of the 2700+ stock exchanges supported by this endpoint.',
      inputSchemaShape: listExchangesInputSchemaShape,
      handler: listExchangesHandler,
    };

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/matteoantoci/mcp-marketstack'

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