Skip to main content
Glama
ukicar

Gallica/BnF MCP Server

by ukicar

sequential_reporting

Generate structured research reports step-by-step using Gallica BnF sources by initializing topics, searching materials, creating bibliographies, and building content sections sequentially.

Instructions

Generate a research report in a sequential, step-by-step manner using Gallica BnF sources.

This tool follows a sequential approach to report generation:

  1. Initialize with a topic

  2. Search for sources

  3. Create bibliography

  4. Create content sections in order

Parameters:

  • topic: Research topic (only needed for initialization)

  • page_count: Number of pages for the report (default: 4)

  • source_count: Number of sources to find (default: 10)

  • search_sources: Set to true to search for sources after initialization

  • section_number: Current section number (1-based)

  • total_sections: Total number of sections in the report

  • title: Title of the current section

  • content: Content for the current section

  • is_bibliography: Whether this section is the bibliography

  • sources_used: List of source IDs used in this section

  • next_section_needed: Whether another section is needed

  • include_graphics: Whether to include images and maps in the report

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
topicNoResearch topic for the report (only needed for initialization)
page_countNoNumber of pages to generate
source_countNoNumber of sources to find
search_sourcesNoSet to true to search for sources after initialization
section_numberYesCurrent section number
total_sectionsYesTotal sections in the report
titleYesTitle of the current section
contentYesContent of the current section
is_bibliographyNoWhether this section is the bibliography
sources_usedNoList of source IDs used in this section
next_section_neededYesWhether another section is needed
include_graphicsNoWhether to include graphics in the report

Implementation Reference

  • Tool registration and schema definition - createSequentialReportingTool defines the tool name, description, input schema with all parameters (topic, page_count, source_count, search_sources, section_number, total_sections, title, content, is_bibliography, sources_used, next_section_needed, include_graphics), and the handler that wraps the SequentialReportingServer.processSection call.
    export function createSequentialReportingTool(reportingServer: SequentialReportingServer) {
      return {
        name: 'sequential_reporting',
        description: `Generate a research report in a sequential, step-by-step manner using Gallica BnF sources.
    
    This tool follows a sequential approach to report generation:
    1. Initialize with a topic
    2. Search for sources
    3. Create bibliography
    4. Create content sections in order
    
    Parameters:
    - topic: Research topic (only needed for initialization)
    - page_count: Number of pages for the report (default: 4)
    - source_count: Number of sources to find (default: 10)
    - search_sources: Set to true to search for sources after initialization
    - section_number: Current section number (1-based)
    - total_sections: Total number of sections in the report
    - title: Title of the current section
    - content: Content for the current section
    - is_bibliography: Whether this section is the bibliography
    - sources_used: List of source IDs used in this section
    - next_section_needed: Whether another section is needed
    - include_graphics: Whether to include images and maps in the report`,
        inputSchema: {
          type: 'object',
          properties: {
            topic: {
              type: 'string',
              description: 'Research topic for the report (only needed for initialization)',
            },
            page_count: {
              type: 'number',
              description: 'Number of pages to generate',
              minimum: 1,
              default: 4,
            },
            source_count: {
              type: 'number',
              description: 'Number of sources to find',
              minimum: 1,
              default: 10,
            },
            search_sources: {
              type: 'boolean',
              description: 'Set to true to search for sources after initialization',
            },
            section_number: {
              type: 'number',
              description: 'Current section number',
              minimum: 1,
            },
            total_sections: {
              type: 'number',
              description: 'Total sections in the report',
              minimum: 1,
            },
            title: {
              type: 'string',
              description: 'Title of the current section',
            },
            content: {
              type: 'string',
              description: 'Content of the current section',
            },
            is_bibliography: {
              type: 'boolean',
              description: 'Whether this section is the bibliography',
            },
            sources_used: {
              type: 'array',
              items: { type: 'number' },
              description: 'List of source IDs used in this section',
            },
            next_section_needed: {
              type: 'boolean',
              description: 'Whether another section is needed',
            },
            include_graphics: {
              type: 'boolean',
              description: 'Whether to include graphics in the report',
              default: false,
            },
          },
          required: ['section_number', 'total_sections', 'title', 'content', 'next_section_needed'],
        },
        handler: async (args: unknown) => {
          // Use a more flexible schema that allows partial validation
          const schema = z.object({
            topic: z.string().optional(),
            page_count: z.number().int().positive().optional(),
            source_count: z.number().int().positive().optional(),
            search_sources: z.boolean().optional(),
            section_number: z.number().int().positive().optional(),
            total_sections: z.number().int().positive().optional(),
            title: z.string().optional(),
            content: z.string().optional(),
            is_bibliography: z.boolean().optional(),
            sources_used: z.array(z.number().int()).optional(),
            next_section_needed: z.boolean().optional(),
            include_graphics: z.boolean().optional(),
          });
    
          const parsed = schema.parse(args);
          return await reportingServer.processSection(parsed);
        },
      };
    }
  • Main handler logic - processSection method implements the sequential reporting workflow: validates input data, handles initialization with topic, searches for sources and graphics, processes report sections, updates state, and returns structured responses with progress tracking and next steps.
    async processSection(inputData: unknown): Promise<{ content: Array<{ text: string }>; isError?: boolean }> {
      try {
        const data = this.validateSectionData(inputData as Record<string, unknown>);
    
        // Initialize with topic
        if ('topic' in data) {
          this.state.topic = data.topic as string;
          this.state.page_count = (data.page_count as number) || DEFAULT_PAGE_COUNT;
          this.state.source_count = (data.source_count as number) || DEFAULT_SOURCE_COUNT;
          this.state.include_graphics = Boolean(data.include_graphics);
          this.state.sources = [];
          this.state.graphics = [];
          this.state.report_sections = [];
          this.state.current_step = 0;
    
          // Create plan
          this.state.plan = this.createPlan(this.state.topic, this.state.page_count);
    
          return {
            content: [{
              text: JSON.stringify({
                topic: this.state.topic,
                pageCount: this.state.page_count,
                sourceCount: this.state.source_count,
                includeGraphics: this.state.include_graphics,
                plan: this.state.plan,
                nextStep: 'Search for sources using natural_language_search or search_by_subject',
              }),
            }],
          };
        }
    
        // Search for sources
        if (data.search_sources) {
          if (!this.state.topic) {
            return {
              content: [{ text: 'Error: No topic specified. Please initialize with a topic first.' }],
              isError: true,
            };
          }
    
          this.state.sources = await this.searchSources(this.state.topic, this.state.source_count);
    
          // If graphics are requested, search for them
          if (this.state.include_graphics) {
            this.state.graphics = await this.searchGraphics(this.state.topic, 5);
          }
    
          this.state.current_step = 1;
    
          return {
            content: [{
              text: JSON.stringify({
                sources: this.state.sources,
                graphics: this.state.include_graphics ? this.state.graphics : [],
                nextStep: 'Create bibliography section',
              }),
            }],
          };
        }
    
        // Process section data
        const validatedInput = this.validateSectionData(inputData as Record<string, unknown>);
    
        // Adjust total sections if needed
        if ((validatedInput.section_number as number) > (validatedInput.total_sections as number)) {
          validatedInput.total_sections = validatedInput.section_number;
        }
    
        // Add section to report
        this.state.report_sections.push(validatedInput as unknown as ReportSection);
    
        // Update current step in plan
        let nextStep = 'Continue writing the report';
        if (this.state.plan) {
          this.state.plan.current_section = validatedInput.section_number as number;
          const sectionIndex = (validatedInput.section_number as number) - 1;
          if (sectionIndex < this.state.plan.sections.length) {
            const nextSectionTitle = this.state.plan.sections[sectionIndex + 1]?.title || 'Next Section';
            nextStep = `Create section ${(validatedInput.section_number as number) + 1}: ${nextSectionTitle}`;
          } else {
            nextStep = 'Report complete';
          }
        }
    
        if (!validatedInput.next_section_needed) {
          nextStep = 'Report complete';
        }
    
        // Calculate progress
        const progress = (this.state.report_sections.length / (validatedInput.total_sections as number)) * 100;
    
        return {
          content: [{
            text: JSON.stringify({
              sectionNumber: validatedInput.section_number,
              totalSections: validatedInput.total_sections,
              nextSectionNeeded: validatedInput.next_section_needed,
              progress: `${progress.toFixed(1)}%`,
              reportSectionsCount: this.state.report_sections.length,
              nextStep: nextStep,
              sources: validatedInput.is_bibliography ? this.state.sources : undefined,
            }),
          }],
        };
      } catch (error) {
        logger.error(`Error processing report section: ${error instanceof Error ? error.message : String(error)}`);
        return {
          content: [{
            text: JSON.stringify({
              error: error instanceof Error ? error.message : String(error),
              status: 'failed',
            }),
          }],
          isError: true,
        };
      }
    }
  • SequentialReportingServer class constructor - initializes the reporting server with GallicaAPI and SearchAPI dependencies, sets up the initial state with default values for page_count (4), source_count (10), and empty arrays for sources, graphics, and report sections.
    export class SequentialReportingServer {
      private searchApi: SearchAPI;
      private state: SequentialReportState;
    
      constructor(_gallicaApi: GallicaAPI, searchApi: SearchAPI) {
        this.searchApi = searchApi;
        this.state = {
          topic: null,
          page_count: DEFAULT_PAGE_COUNT,
          source_count: DEFAULT_SOURCE_COUNT,
          sources: [],
          report_sections: [],
          plan: null,
          current_step: 0,
          include_graphics: false,
          graphics: [],
        };
      }
  • Type definition for SequentialReportState schema - defines the state structure including topic, page_count, source_count, sources array, report_sections array, plan, current_step, include_graphics, and graphics array.
    export interface SequentialReportState {
      topic: string | null;
      page_count: number;
      source_count: number;
      sources: Source[];
      report_sections: ReportSection[];
      plan: ReportPlan | null;
      current_step: number;
      include_graphics: boolean;
      graphics: Graphic[];
    }
  • MCP server registration - instantiates SequentialReportingServer with gallicaApi and searchApi (line 73), creates the sequentialReporting tool using createSequentialReportingTool (line 91), and adds it to the tools array that is registered with the MCP server (line 106).
    const reportingServer = new SequentialReportingServer(gallicaApi, searchApi);
    
    // Register search tools (7 tools matching Python)
    const searchByTitle = createSearchByTitleTool(searchApi);
    const searchByAuthor = createSearchByAuthorTool(searchApi);
    const searchBySubject = createSearchBySubjectTool(searchApi);
    const searchByDate = createSearchByDateTool(searchApi);
    const searchByDocumentType = createSearchByDocumentTypeTool(searchApi);
    const advancedSearch = createAdvancedSearchTool(searchApi);
    const naturalLanguageSearch = createNaturalLanguageSearchTool(searchApi);
    
    // Register extended item tools (4 new tools)
    const getItemDetails = createGetItemDetailsTool(itemsClient);
    const getItemPages = createGetItemPagesTool(itemsClient);
    const getPageImage = createGetPageImageTool(iiifClient);
    const getPageText = createGetPageTextTool(textClient);
    
    // Register sequential reporting tool
    const sequentialReporting = createSequentialReportingTool(reportingServer);
    
    // Register all tools with error handling
    const tools = [
      searchByTitle,
      searchByAuthor,
      searchBySubject,
      searchByDate,
      searchByDocumentType,
      advancedSearch,
      naturalLanguageSearch,
      getItemDetails,
      getItemPages,
      getPageImage,
      getPageText,
      sequentialReporting,
Behavior3/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. It describes the sequential process flow, which is valuable context beyond basic functionality. However, it doesn't mention important behavioral aspects like whether this is a read-only or write operation, potential rate limits, authentication requirements, or what happens if the process is interrupted mid-sequence. The description adds some process context but leaves significant behavioral gaps.

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 reasonably structured with a clear purpose statement followed by sequential steps and parameter list. However, the parameter list is somewhat redundant given the comprehensive schema descriptions. The description could be more concise by focusing on process flow rather than repeating parameter names. Still, it's not excessively verbose and maintains focus on the tool's purpose.

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?

For a complex 12-parameter tool with no annotations and no output schema, the description provides adequate basic context about the sequential process. However, it doesn't explain what the tool returns (no output schema), doesn't cover error conditions, and doesn't provide enough guidance on how to orchestrate the multi-step process effectively. Given the complexity, more complete usage guidance would be helpful.

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?

Schema description coverage is 100%, so the schema already documents all 12 parameters thoroughly. The description lists all parameters but doesn't add meaningful semantic context beyond what's in the schema descriptions. It provides a parameter list but no additional guidance on how parameters interact in the sequential process or which parameters are needed at which steps. Baseline 3 is appropriate when schema does the heavy lifting.

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 tool's purpose: 'Generate a research report in a sequential, step-by-step manner using Gallica BnF sources.' It specifies the verb ('generate'), resource ('research report'), and approach ('sequential, step-by-step'). However, it doesn't explicitly differentiate from sibling tools like 'advanced_search' or 'natural_language_search' which are search-focused rather than report generation tools.

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

Usage Guidelines3/5

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

The description implies usage through its sequential step explanation (initialize, search, create bibliography, create sections), suggesting this tool should be used for multi-step report generation. However, it doesn't provide explicit guidance on when to use this vs. simpler search tools or when not to use it (e.g., for quick lookups). No alternative tools are mentioned for similar tasks.

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/ukicar/sweet-bnf'

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