Skip to main content
Glama

mcp_sparql_execute_query

Execute SPARQL queries on GraphDB endpoints and retrieve results in JSON, XML, CSV, or TSV formats for ontology data analysis and manipulation.

Instructions

SPARQL 쿼리를 실행하고 결과를 반환합니다

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
endpointNoSPARQL 엔드포인트 URL
explainNo쿼리 실행 계획 반환 여부
formatNo결과 형식(json, xml, csv, tsv)
queryYes실행할 SPARQL 쿼리
repositoryNo쿼리를 실행할 리포지토리 이름

Implementation Reference

  • The primary handler function for the 'mcp_sparql_execute_query' tool. It receives arguments, calls SparqlService.executeQuery, formats the result as JSON/text, and returns a ToolResponse or error message.
    async handler(args: ExecuteQueryArgs): Promise<ToolResponse> {
      try {
        const result = await sparqlService.executeQuery(args.query, args.repository, args.format);
        
        // 결과를 서식화하여 반환
        return {
          content: [{
            type: 'text',
            text: typeof result === 'object' ? JSON.stringify(result, null, 2) : result.toString()
          }]
        };
      } catch (error) {
        return {
          content: [{
            type: 'text',
            text: `쿼리 실행 오류: ${error instanceof Error ? error.message : String(error)}`
          }]
        };
      }
    }
  • The JSON schema defining the input parameters for the tool, including required 'query' and optional fields like repository, endpoint, format, and explain.
    inputSchema: {
      type: 'object',
      properties: {
        query: {
          type: 'string',
          description: '실행할 SPARQL 쿼리'
        },
        repository: {
          type: 'string',
          description: '쿼리를 실행할 리포지토리 이름'
        },
        endpoint: {
          type: 'string',
          description: 'SPARQL 엔드포인트 URL'
        },
        format: {
          type: 'string',
          enum: ['json', 'xml', 'csv', 'tsv'],
          description: '결과 형식(json, xml, csv, tsv)'
        },
        explain: {
          type: 'boolean',
          description: '쿼리 실행 계획 반환 여부'
        }
      },
      required: ['query']
    },
  • The complete tool definition object that registers 'mcp_sparql_execute_query' in the exported tools array, used by the MCP server.
    {
      name: 'mcp_sparql_execute_query',
      description: 'SPARQL 쿼리를 실행하고 결과를 반환합니다',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: '실행할 SPARQL 쿼리'
          },
          repository: {
            type: 'string',
            description: '쿼리를 실행할 리포지토리 이름'
          },
          endpoint: {
            type: 'string',
            description: 'SPARQL 엔드포인트 URL'
          },
          format: {
            type: 'string',
            enum: ['json', 'xml', 'csv', 'tsv'],
            description: '결과 형식(json, xml, csv, tsv)'
          },
          explain: {
            type: 'boolean',
            description: '쿼리 실행 계획 반환 여부'
          }
        },
        required: ['query']
      },
      async handler(args: ExecuteQueryArgs): Promise<ToolResponse> {
        try {
          const result = await sparqlService.executeQuery(args.query, args.repository, args.format);
          
          // 결과를 서식화하여 반환
          return {
            content: [{
              type: 'text',
              text: typeof result === 'object' ? JSON.stringify(result, null, 2) : result.toString()
            }]
          };
        } catch (error) {
          return {
            content: [{
              type: 'text',
              text: `쿼리 실행 오류: ${error instanceof Error ? error.message : String(error)}`
            }]
          };
        }
      }
    },
  • The core SparqlService.executeQuery method that performs the actual HTTP POST request to the SPARQL endpoint to execute the query and parse the response.
    async executeQuery(query: string, repository?: string, format: string = 'json', explain = false): Promise<any> {
      const repo = repository || this.config.defaultRepository;
      const endpoint = this.config.endpoint;
      const url = explain 
        ? `${endpoint}/repositories/${repo}/explain`
        : `${endpoint}/repositories/${repo}`;
      
      try {
        const response = await fetch(url, {
          method: 'POST',
          headers: {
            'Content-Type': 'application/sparql-query',
            'Accept': format === 'json' ? 'application/sparql-results+json' : `application/sparql-results+${format}`
          },
          body: query
        });
    
        if (!response.ok) {
          throw new Error(`SPARQL 쿼리 실행 오류 (${response.status}): ${await response.text()}`);
        }
    
        if (format === 'json') {
          return await response.json();
        } else {
          return await response.text();
        }
      } catch (error) {
        console.error('SPARQL 쿼리 실행 중 오류:', error);
        throw error;
      }
    }
  • TypeScript interface defining the ExecuteQueryArgs type used in the tool handler signature for type safety.
    export interface ExecuteQueryArgs {
      query: string;
      repository?: string;
      endpoint?: string;
      format?: 'json' | 'xml' | 'csv' | 'tsv';
      explain?: boolean;
    }
  • src/index.ts:26-26 (registration)
    MCP server capabilities declaration advertising support for the 'mcp_sparql_execute_query' tool.
    mcp_sparql_execute_query: true,
Behavior2/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. While it mentions executing queries and returning results, it doesn't describe important behavioral aspects: whether this is read-only or can modify data, authentication requirements, rate limits, error handling, or what format the results take. For a query execution tool with zero annotation coverage, this leaves significant gaps in understanding how the tool behaves.

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

Conciseness5/5

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

The description is extremely concise - a single sentence that directly states the tool's core function. There's zero wasted language or unnecessary elaboration. It's appropriately sized for what it communicates and is front-loaded with the essential information.

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

Completeness2/5

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

Given the complexity of a SPARQL query execution tool with 5 parameters, no annotations, and no output schema, the description is insufficiently complete. It doesn't explain what kind of results are returned, error conditions, authentication requirements, or how it differs from other SPARQL tools on the server. For a tool that executes potentially complex queries against endpoints, more context is needed for effective use.

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?

The schema description coverage is 100%, meaning all parameters are documented in the schema itself. The description doesn't add any parameter semantics beyond what's already in the schema - it doesn't explain parameter relationships, provide examples, or clarify usage patterns. According to the scoring rules, when schema coverage is high (>80%), the baseline is 3 even with no parameter information in the description.

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: 'SPARQL 쿼리를 실행하고 결과를 반환합니다' (Execute SPARQL query and return results). This specifies both the verb (execute) and resource (SPARQL query). However, it doesn't differentiate from sibling SPARQL tools like mcp_sparql_update or mcp_sparql_list_graphs, which prevents a score of 5.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. There are multiple sibling SPARQL tools (get_resource_info, list_graphs, list_repositories, update) that likely serve different purposes, but the description doesn't indicate when this execute_query tool is appropriate versus those other options. No usage context or exclusions are mentioned.

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

Related 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/bigdata-coss/agent_mcp'

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