Skip to main content
Glama
kupad95

UK Parliament MCP Server

by kupad95

analyze_patterns

Detect voting patterns like close divisions, government defeats, and party rebellion rates across parliamentary votes for trend analysis.

Instructions

Detect patterns across many parliamentary votes: 'close_votes' finds divisions with a small margin (near-misses or knife-edge votes), 'government_defeats' finds votes the government lost, 'party_rebellion_rate' shows which parties rebel most by percentage of votes cast. Use for trend analysis across many divisions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pattern_typeYesThe pattern to detect.
houseNoWhich house to analyse. Defaults to Commons.
daysNoHow many days back to scan. Default 365.
thresholdNoFor close_votes: maximum majority to count as close. Default 10.
max_divisionsNoMaximum divisions to scan. Default 100.
limitNoMaximum results to return. Default 20.

Implementation Reference

  • Main handler for analyze_patterns tool. Dispatches to sub-handlers based on pattern_type: close_votes, government_defeats, or party_rebellion_rate.
    export async function handlePatternsTool(
      name: string,
      args: Record<string, unknown>
    ): Promise<string> {
      try {
        if (name !== "analyze_patterns") {
          throw new Error(`Unknown tool: ${name}`);
        }
    
        const patternType = args.pattern_type as string;
        const house = (args.house as "Commons" | "Lords") ?? "Commons";
        const days = (args.days as number) ?? 365;
        const maxDivisions = (args.max_divisions as number) ?? 100;
        const limit = (args.limit as number) ?? 20;
    
        const startDate = daysAgoISO(days);
        const summaries = await fetchDivisionSummaries(house, startDate, maxDivisions);
    
        if (patternType === "close_votes") {
          return handleCloseVotes(summaries, house, days, limit, args);
        } else if (patternType === "government_defeats") {
          return handleGovernmentDefeats(summaries, house, days, limit);
        } else if (patternType === "party_rebellion_rate") {
          return await handlePartyRebellionRate(summaries, house, days, limit);
        } else {
          throw new Error(
            `Unknown pattern_type: ${patternType}. Use 'close_votes', 'government_defeats', or 'party_rebellion_rate'.`
          );
        }
      } catch (error) {
        const message =
          error instanceof Error ? error.message : "An unknown error occurred.";
        throw new Error(message);
      }
    }
  • Tool definition and input schema for analyze_patterns. Declares 'analyze_patterns' with enum pattern_type (close_votes, government_defeats, party_rebellion_rate), optional house (Commons/Lords), days, threshold, max_divisions, and limit.
    export const patternsTools = [
      {
        name: "analyze_patterns",
        description:
          "Detect patterns across many parliamentary votes: 'close_votes' finds divisions with a small margin (near-misses or knife-edge votes), 'government_defeats' finds votes the government lost, 'party_rebellion_rate' shows which parties rebel most by percentage of votes cast. Use for trend analysis across many divisions.",
        inputSchema: {
          type: "object",
          properties: {
            pattern_type: {
              type: "string",
              enum: ["close_votes", "government_defeats", "party_rebellion_rate"],
              description: "The pattern to detect.",
            },
            house: {
              type: "string",
              enum: ["Commons", "Lords"],
              description: "Which house to analyse. Defaults to Commons.",
            },
            days: {
              type: "number",
              description: "How many days back to scan. Default 365.",
            },
            threshold: {
              type: "number",
              description:
                "For close_votes: maximum majority to count as close. Default 10.",
            },
            max_divisions: {
              type: "number",
              description: "Maximum divisions to scan. Default 100.",
            },
            limit: {
              type: "number",
              description: "Maximum results to return. Default 20.",
            },
          },
          required: ["pattern_type"],
        },
      },
    ];
  • src/index.ts:11-12 (registration)
    Import of patternsTools and handlePatternsTool from patterns.ts module.
    import { patternsTools, handlePatternsTool } from "./tools/patterns.js";
    import { findTools, handleFindTool } from "./tools/find.js";
  • src/index.ts:20-26 (registration)
    Registration of patternsTools (including analyze_patterns) into the allTools array for ListToolsRequestSchema.
    const allTools = [
      ...rankTools,
      ...eventsTools,
      ...patternsTools,
      ...findTools,
      ...queryTools,
    ];
  • src/index.ts:37-38 (registration)
    Routing of 'analyze_patterns' tool name to handlePatternsTool in the CallToolRequestSchema handler.
    else if (name === "analyze_patterns") result = await handlePatternsTool(name, safeArgs);
    else if (name === "find_entities") result = await handleFindTool(name, safeArgs);
Behavior3/5

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

No annotations provided, so the description carries full burden. It explains pattern types but does not disclose potential behavioral traits like read-only nature, rate limits, or error handling. Basic transparency is achieved.

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

Conciseness4/5

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

The description is a single sentence followed by a list of pattern types, front-loading the main purpose. It is fairly concise, though the pattern explanations could be slightly more streamlined.

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

Completeness3/5

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

Given the tool has 6 parameters and no output schema, the description does not explain return values or behavior for edge cases. It covers pattern selection but omits output details, leaving some gaps.

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

Parameters4/5

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

Schema description coverage is 100% with descriptions for all parameters. The description adds value by elaborating on the pattern_type enum values, explaining what each pattern means beyond the schema's simple description.

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

Purpose5/5

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

The description clearly states the tool detects patterns across many parliamentary votes and enumerates three specific pattern types with brief explanations. It distinguishes itself from siblings which focus on entities, events, querying, and ranking.

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

Usage Guidelines4/5

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

The description states 'Use for trend analysis across many divisions,' providing clear context. However, it does not explicitly mention when not to use or direct to alternative tools, though siblings imply different use cases.

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/kupad95/uk-parliament-mcp-server'

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