Skip to main content
Glama
psalzman
by psalzman

search_candidates

Find U.S. political candidates by name, state, office, or election year to access Federal Election Commission campaign finance data.

Instructions

Search for candidates by name or other criteria

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesCandidate name search string
stateNoOptional: Two-letter state code
officeNoOptional: H for House, S for Senate, P for President
election_yearNoOptional: Filter by election year

Implementation Reference

  • The handler function that implements the search_candidates tool logic: validates arguments using Zod, queries the OpenFEC API endpoint /candidates/search, and returns the response as JSON text content.
    private async handleSearchCandidates(args: any) { const schema = z.object({ name: z.string(), state: z.string().optional(), office: z.enum(['H', 'S', 'P']).optional(), election_year: z.number().optional(), }); const { name, state, office, election_year } = schema.parse(args); this.rateLimiter.consumeToken(); const response = await this.axiosInstance.get('/candidates/search', { params: { q: name, state, office, election_year, }, }); return { content: [ { type: 'text', text: JSON.stringify(response.data, null, 2), }, ], }; }
  • Input schema definition for the search_candidates tool, defining parameters like name (required), state, office, and election_year.
    inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Candidate name search string', }, state: { type: 'string', description: 'Optional: Two-letter state code', }, office: { type: 'string', description: 'Optional: H for House, S for Senate, P for President', enum: ['H', 'S', 'P'], }, election_year: { type: 'number', description: 'Optional: Filter by election year', }, }, required: ['name'], },
  • src/server.ts:129-155 (registration)
    Registration of the search_candidates tool in the ListTools response, including name, description, and input schema.
    { name: 'search_candidates', description: 'Search for candidates by name or other criteria', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Candidate name search string', }, state: { type: 'string', description: 'Optional: Two-letter state code', }, office: { type: 'string', description: 'Optional: H for House, S for Senate, P for President', enum: ['H', 'S', 'P'], }, election_year: { type: 'number', description: 'Optional: Filter by election year', }, }, required: ['name'], }, },
  • src/server.ts:449-450 (registration)
    Dispatch case in CallToolRequest handler that routes search_candidates calls to the handleSearchCandidates method.
    case 'search_candidates': return await this.handleSearchCandidates(request.params.arguments);
  • Zod runtime validation schema used inside the handler, matching the tool's inputSchema.
    const schema = z.object({ name: z.string(), state: z.string().optional(), office: z.enum(['H', 'S', 'P']).optional(), election_year: z.number().optional(), });

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