Skip to main content
Glama
psalzman

MCP OpenFEC Server

by psalzman

get_candidate_financials

Retrieve campaign finance data for a specific candidate and election year from Federal Election Commission records.

Instructions

Get financial data for a candidate

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
candidate_idYesFEC candidate ID
election_yearYesElection year to get data for

Implementation Reference

  • The handler function for 'get_candidate_financials' tool. Validates input using Zod schema, consumes rate limit token, fetches financial totals from OpenFEC API endpoint `/candidate/{candidate_id}/totals` for the specified election year, and returns the JSON response as text content.
    private async handleGetCandidateFinancials(args: any) {
      const schema = z.object({
        candidate_id: z.string(),
        election_year: z.number(),
      });
    
      const { candidate_id, election_year } = schema.parse(args);
      this.rateLimiter.consumeToken();
    
      const response = await this.axiosInstance.get(`/candidate/${candidate_id}/totals`, {
        params: { election_year }
      });
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(response.data, null, 2),
          },
        ],
      };
    }
  • Input schema definition for the 'get_candidate_financials' tool, specifying required candidate_id (string) and election_year (number).
    inputSchema: {
      type: 'object',
      properties: {
        candidate_id: {
          type: 'string',
          description: 'FEC candidate ID',
        },
        election_year: {
          type: 'number',
          description: 'Election year to get data for',
        },
      },
      required: ['candidate_id', 'election_year'],
    },
  • src/server.ts:111-128 (registration)
    Registration of the 'get_candidate_financials' tool in the ListTools response, including name, description, and input schema.
    {
      name: 'get_candidate_financials',
      description: 'Get financial data for a candidate',
      inputSchema: {
        type: 'object',
        properties: {
          candidate_id: {
            type: 'string',
            description: 'FEC candidate ID',
          },
          election_year: {
            type: 'number',
            description: 'Election year to get data for',
          },
        },
        required: ['candidate_id', 'election_year'],
      },
    },
  • src/server.ts:453-454 (registration)
    Switch case in CallToolRequest handler that dispatches to the specific tool handler.
    case 'get_candidate_financials':
      return await this.handleGetCandidateFinancials(request.params.arguments);

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/psalzman/mcp-openfec'

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