### Example Tool Execution Flow (Markdown) Source: https://github.com/thecolorred/data-store-mcp/blob/main/README.md Shows a sequence of operations described in markdown that lead to the execution of multiple MCP tools. This example covers table creation, data insertion, and data retrieval, followed by data modification and subsequent retrieval. ```markdown In the sqlite database, do the following: 1. Create a table `letter_word` with two columns: `letter`, `word`. 2. Insert all letters from a-z and generate a word for it. 3. Show me the content of the new table. 1. Capitalize each word in the word column. 2. Show me the first 10 rows from the updated table. ``` -------------------------------- ### Example of using Schema and REST API connection Source: https://github.com/thecolorred/data-store-mcp/blob/main/README.md This example demonstrates a natural language query that leverages the schema from a 'mysql' database to then select data from a 'rest' endpoint. This showcases how different data sources can be chained together. ```markdown Query the "mysql" database for the #schema and then #select the `posts` endpoint using "rest". ``` -------------------------------- ### MongoDB Connection Configuration Example Source: https://context7.com/thecolorred/data-store-mcp/llms.txt This JSON object demonstrates the configuration structure for connecting to a MongoDB instance. It specifies the connection ID, type, a description, and connection options including the URL. This file would typically be located in a configuration directory like `.vscode/`. ```json { "id": "my-mongodb", "type": "mongodb", "description": "Main application database", "options": { "url": "mongodb://localhost:27017/myapp" } } ``` -------------------------------- ### Select Tool API Source: https://context7.com/thecolorred/data-store-mcp/llms.txt Executes SELECT queries on SQL databases or GET requests on HTTP APIs. This tool allows for parameterized queries and specifying request details for API calls. ```APIDOC ## POST /tools/select ### Description Executes SELECT queries on SQL databases or GET requests on HTTP APIs. ### Method POST ### Endpoint /tools/select ### Parameters #### Request Body - **connectionId** (string) - Required - The ID of the data source connection. - **payload** (object | string) - Required - The query or request details. For SQL, it includes `sql` and optional `params`. For HTTP, it includes `endpoint`, `method` (defaults to GET), and optional `headers` and `body`. ### Request Example ```json { "connectionId": "my-mysql-connection", "payload": { "sql": "SELECT * FROM users WHERE status = ? AND created_at > ?", "params": ["active", "2024-01-01"] } } ``` ### Response #### Success Response (200) - **result** (string) - The result of the SELECT query or GET request. #### Response Example ```json [ { "id": 1, "name": "John Doe", "status": "active" }, { "id": 2, "name": "Jane Smith", "status": "active" } ] ``` ``` -------------------------------- ### Execute SELECT Queries (TypeScript) Source: https://context7.com/thecolorred/data-store-mcp/llms.txt The select tool executes SELECT queries on SQL databases or GET requests on HTTP APIs. It requires a connection ID and a payload containing the SQL query or API endpoint details. It returns the query results or API response. ```typescript server.tool( 'select', 'Runs a select query on the data source', { connectionId: z.string(), payload: z.union([z.record(z.any()), z.string()]) }, async request => { const { source } = await getSource(request, await getFolders()); if (!isAllowed(source.connectionConfig, 'select')) { throw new Error('Select tool is not allowed for this connection'); } // Validates SQL is a SELECT statement if (source instanceof SqlDataSource && !source.isSelect()) { return returnText('The provided SQL query is not a SELECT statement.'); } const result = await source.select(); source.close(); return returnText(result); } ); // Example: MySQL select with parameters { "connectionId": "my-mysql-connection", "payload": { "sql": "SELECT * FROM users WHERE status = ? AND created_at > ?", "params": ["active", "2024-01-01"] } } // Example: REST API GET request { "connectionId": "my-rest-api", "payload": { "endpoint": "https://api.example.com/posts/123", "method": "GET", "headers": { "Authorization": "Bearer token123" } } } ``` -------------------------------- ### Ignoring Data Store Connection Files in .gitignore Source: https://github.com/thecolorred/data-store-mcp/blob/main/README.md Provides examples of how to configure a .gitignore file to exclude sensitive data store connection files. It shows patterns for ignoring specific JSON files in the .vscode folder and how to ignore an entire subfolder. ```gitignore # To ignore files in the root .vscode folder: .vscode/*connection*.json .vscode/*store*.json # OR ignore an entire folder within .vscode: .vscode/stores ``` -------------------------------- ### AWS S3 Object Operations Source: https://github.com/thecolorred/data-store-mcp/blob/main/src/docs/connections.md Perform operations on AWS S3 objects using a 'payload' object with 'method', 'bucket', 'key', and other relevant parameters. Methods include GET, SELECT, INSERT, UPDATE, and DELETE. ```json { "method": "GET", "bucket": "my-bucket", "key": "path/to/object.txt" } ``` ```json { "method": "SELECT", "bucket": "my-bucket", "key": "prefix/", "maxResults": 10 } ``` ```json { "method": "INSERT", "bucket": "my-bucket", "key": "new/object.txt", "sourceType": "raw", "sourceValue": "This is the content to upload." } ``` ```json { "method": "UPDATE", "bucket": "my-bucket", "key": "existing/object.txt", "sourceType": "path", "sourceValue": "/local/path/to/file.txt" } ``` ```json { "method": "DELETE", "bucket": "my-bucket", "key": "object/to/delete.txt" } ``` -------------------------------- ### MongoDB Select Operation Payload Example Source: https://context7.com/thecolorred/data-store-mcp/llms.txt This JSON payload is used to instruct the MongoDB data source to perform a 'SELECT' operation. It includes the connection ID, the method, the target table name, and a filter object to specify the selection criteria. The filter uses MongoDB's query syntax. ```json { "connectionId": "my-mongodb", "payload": { "method": "SELECT", "tableName": "users", "filter": { "status": "active", "age": { "$gt": 21 } } } } ``` -------------------------------- ### Configure GraphQL Connection for Blog Posts Source: https://github.com/thecolorred/data-store-mcp/blob/main/README.md Sets up a GraphQL connection specifying the API endpoint URL and optional headers for authentication. The 'description' field provides context to the agent about the GraphQL operation. ```json { "id": "my-graphql", "type": "graphql", "description": "A GraphQL operation for managing blog posts.", "options": { "url": "https://api.example.com/v1/graphql", "description": "The GraphQL endpoint for the API.", "headers": { "Authorization": "Bearer YOUR_ACCESS_TOKEN" } } } ``` -------------------------------- ### SQL Table Creation with Comments Source: https://github.com/thecolorred/data-store-mcp/blob/main/README.md Demonstrates how to create a SQL table with comments for both the table itself and its columns. This enhances data context for agents. Assumes a SQL database that supports the 'comment' keyword. ```sql create table users ( id int(10) unsigned primary key not null auto_increment comment 'The unique identifier for the user', name varchar(255) not null comment 'The name of the user', email varchar(255) not null comment 'The email address of the user', ) comment 'This table stores information about users in the system'; ``` -------------------------------- ### Execute SQL Queries with SELECT, INSERT, UPDATE, DELETE Tools Source: https://github.com/thecolorred/data-store-mcp/blob/main/src/docs/connections.md To execute SQL queries, provide an 'sql' key with the query string. Use the #select, #insert, #update, and #delete tools for their respective operations. Other queries should use the #mutation tool. Ensure correct schema knowledge before execution. ```text #select { "sql": "SELECT column1, column2 FROM your_table WHERE condition;" } #insert { "sql": "INSERT INTO your_table (column1, column2) VALUES (value1, value2);" } #update { "sql": "UPDATE your_table SET column1 = value1 WHERE condition;" } #delete { "sql": "DELETE FROM your_table WHERE condition;" } #mutation { "sql": "-- any other SQL statement --" } ``` -------------------------------- ### Configure REST Connection for Blog Posts Source: https://github.com/thecolorred/data-store-mcp/blob/main/README.md Defines a REST connection with a URL, optional headers for authentication, and an array of endpoints. Each endpoint can be a simple URL string or an object specifying the URL, method, and search parameters. The 'description' field helps agents understand the purpose of each endpoint. ```json { "id": "my-rest", "type": "rest", "description": "A REST operation for managing blog posts.", "options": { "headers": { "Authorization": "Bearer YOUR_ACCESS_TOKEN" }, "endpoints": [ "https://api.example.com/posts", { "url": "https://api.example.com/posts/:id", "description": "Get a specific post by ID" }, { "url": "https://api.example.com/search", "description": "Finds posts by title or content", "search": { "query": "The term to search for" } } ] } } ``` -------------------------------- ### MCP Data Store Tools Source: https://github.com/thecolorred/data-store-mcp/blob/main/README.md Documentation for the tools available in the MCP to interact with data stores, including connections, payload, schema, and command execution. ```APIDOC ## MCP Data Store Tools ### `connections` Tool #### Description Retrieves all defined connections from configuration files (`connections.json`, `stores.json`, `*.connection.json`, `*.store.json`) in the `.vscode` folder. #### Support Full support. #### Note Recommended to keep enabled to allow the agent to discover available data source connections. ### `payload` Tool #### Description Fetches the necessary payload (data structure) required for an operation on a specific data source. The payload structure varies based on the data source type and operation. #### Support Full support. #### Note Recommended to keep enabled for the agent to correctly format data for operations. ### `schema` Tool #### Description Retrieves the full data store schema. It can also fetch the schema for a specific table if requested. #### Support Partial support. May not be available for all data sources (e.g., some API data sources). ### Executable Commands #### `select` Command ##### Description Executes `SELECT` statements on the currently connected database. ##### Support Full support. ##### Note Queries are validated using `node-sql-parser`. For security, it's recommended to use a database user with read-only permissions. #### `mutation` Command ##### Description Executes any type of SQL query, including data modification statements. ##### Support Full support. ##### Note For GraphQL, this tool cannot distinguish between INSERT, UPDATE, or DELETE operations. #### `insert` Command ##### Description Executes `INSERT` statements on the current database connection. ##### Support Partial support. ##### Note For GraphQL, the tool cannot determine if a mutation represents an INSERT, UPDATE, or DELETE operation. ``` -------------------------------- ### GraphQL Connection Configuration Source: https://github.com/thecolorred/data-store-mcp/blob/main/README.md Defines the structure for a GraphQL connection, including URL, optional headers, and a description. ```APIDOC ## GraphQL Connection ### Description A GraphQL connection is configured with a URL for the GraphQL endpoint and optional headers for authentication or other request specifics. ### Structure - **url** (string) - The URL of the GraphQL endpoint. - **headers** (object, optional) - Key-value pairs for request headers. - **description** (string, optional) - A description of the GraphQL API's purpose. ### Example Configuration ```json { "id": "my-graphql-connection", "type": "graphql", "description": "GraphQL API for managing blog posts.", "options": { "url": "https://api.example.com/v1/graphql", "headers": { "Authorization": "Bearer YOUR_ACCESS_TOKEN" } } } ``` ``` -------------------------------- ### Sample MySQL Database Connection Configuration Source: https://github.com/thecolorred/data-store-mcp/blob/main/README.md This JSON object defines a connection to a MySQL database. It includes a unique 'id', the 'type' set to 'mysql', a descriptive string, and an 'options' object containing specific MySQL connection details such as host, user, password, and database name. ```json { "id": "my-mysql-connection", "type": "mysql", "description": "A connection that stores information about the blog on my website.", "options": { "host": "localhost", "user": "root", "password": "password", "database": "blog" } } ``` -------------------------------- ### Forcing Tool Execution with #tool Syntax Source: https://github.com/thecolorred/data-store-mcp/blob/main/README.md Illustrates how to explicitly instruct the agent to use a specific tool by prefixing the tool name with '#'. This is useful when the agent might otherwise fail to identify or select the correct tool, such as the 'select' tool. ```plaintext #select 5 users from the users table ``` -------------------------------- ### REST API Operations Source: https://github.com/thecolorred/data-store-mcp/blob/main/src/docs/connections.md Instructions for executing REST API operations, detailing required and optional parameters. ```APIDOC ## REST API Operations ### Description When executing a REST operation, you should provide specific keys for the request, including the endpoint, payload, method, and headers. ### Method GET | POST | PUT | DELETE (Defaults to GET) ### Endpoint [Full endpoint path with query parameters] ### Parameters #### Query Parameters - **key** (string) - Optional - Key-value pairs for query string (e.g., `?key=value`). #### Request Body - **payload** (object) - Optional - The payload to send in the request body. #### Headers - **headers** (object) - Optional - Headers to include in the request. ### Request Example ```json { "endpoint": "/users?status=active", "method": "GET", "payload": { "name": "Jane Doe" }, "headers": { "Authorization": "Bearer YOUR_TOKEN" } } ``` ### Response #### Success Response (200) - The response body depends on the specific REST API endpoint. #### Response Example ```json { "message": "Success" } ``` ``` -------------------------------- ### Insert Tool API Source: https://context7.com/thecolorred/data-store-mcp/llms.txt Executes INSERT statements on databases or POST requests on HTTP APIs. Supports parameterized SQL inserts and structured data for NoSQL or API inserts. ```APIDOC ## POST /tools/insert ### Description Executes INSERT statements on databases or POST requests on HTTP APIs. ### Method POST ### Endpoint /tools/insert ### Parameters #### Request Body - **connectionId** (string) - Required - The ID of the data source connection. - **payload** (object | string) - Required - The insert details. For SQL, it includes `sql` and optional `params`. For NoSQL/APIs, it can include `method`, `tableName`, and `value`. ### Request Example ```json { "connectionId": "my-mysql-connection", "payload": { "sql": "INSERT INTO users (name, email, status) VALUES (?, ?, ?)", "params": ["John Doe", "john@example.com", "active"] } } ``` ### Response #### Success Response (200) - **result** (object) - Details of the insert operation, such as `insertId` and `affectedRows`. #### Response Example ```json { "insertId": 42, "affectedRows": 1 } ``` ``` -------------------------------- ### Register MCP Server for Data Store Interactions (TypeScript) Source: https://context7.com/thecolorred/data-store-mcp/llms.txt Activates the Visual Studio Code extension by registering an MCP server definition provider. It watches for connection configuration files in the .vscode directory and exposes a data store MCP server via stdio communication. ```typescript import * as vscode from 'vscode'; import * as path from 'path'; // Extension activation - automatically triggered when connection files are detected export function activate(context: vscode.ExtensionContext) { const didChangeEmitter = new vscode.EventEmitter(); // Watch for connection configuration changes const watcher = vscode.workspace.createFileSystemWatcher( '.vscode/**/{connections,stores}.json,.vscode/**/*.{connection,store}.json' ); watcher.onDidChange(() => didChangeEmitter.fire()); watcher.onDidCreate(() => didChangeEmitter.fire()); watcher.onDidDelete(() => didChangeEmitter.fire()); // Register the MCP server definition provider const dataStoreMcpProvider = vscode.lm.registerMcpServerDefinitionProvider('data-store-mcp', { onDidChangeMcpServerDefinitions: didChangeEmitter.event, provideMcpServerDefinitions: async () => { const folders = vscode.workspace.workspaceFolders ?? []; return [ new vscode.McpStdioServerDefinition('Data Store', 'node', [ path.posix.join(__dirname, 'mcp/server.js'), JSON.stringify(folders.map(folder => folder.uri.fsPath)), __dirname, ]), ]; }, }); context.subscriptions.push(dataStoreMcpProvider); } ``` -------------------------------- ### List Data Source Connections (TypeScript) Source: https://context7.com/thecolorred/data-store-mcp/llms.txt Registers an MCP tool named 'connections' that lists all available data source connections defined in configuration files within the .vscode directory. It scans for connection files, parses them, and validates for duplicate connection IDs. ```typescript // MCP Tool registration in server.ts server.tool( 'connections', 'Lists all available data source connections', async () => { const folders = await getFolders(); // Scans .vscode for connection files const connections = await Promise.all( folders.map(async folder => { const data = JSON.parse(await fs.readFile(folder.dbFile, 'utf-8')); return data; }) ); // Validates no duplicate connection IDs exist const connectionIds = new Map(); connections.forEach((conn, index) => { const id = Array.isArray(conn) ? conn[0].id : conn.id; if (!connectionIds.has(id)) connectionIds.set(id, []); connectionIds.get(id).push(folders[index].dbFile); }); return returnText(connections, docs, parameterInformation); } ); // Example connection configuration: .vscode/my-db.connection.json { "id": "my-mysql-connection", "type": "mysql", "description": "Production blog database", "options": { "host": "localhost", "user": "root", "password": "password", "database": "blog" } } ``` -------------------------------- ### REST Connection Configuration Source: https://github.com/thecolorred/data-store-mcp/blob/main/README.md Defines the structure for a REST connection, including URL, optional headers, and endpoints with their methods and descriptions. ```APIDOC ## REST Connection ### Description A REST connection configuration includes a base URL, optional headers for authentication, and a list of endpoints. Each endpoint can be a simple URL or an object specifying the URL, HTTP method, and a description. ### Structure - **url** (string) - The base URL for the REST API. - **headers** (object, optional) - Key-value pairs for request headers (e.g., Authorization). - **endpoints** (array) - A list of available API endpoints. - Each endpoint can be a string URL or an object: - **url** (string) - The specific endpoint path. - **method** (string, optional) - The HTTP method (GET, POST, PUT, DELETE). Defaults to GET. - **description** (string, optional) - A description of the endpoint's purpose. - **search** (object, optional) - Defines query parameters for the endpoint. - **key** (string) - The query parameter key. - **value** (string) - The query parameter value. ### Example Configuration ```json { "id": "my-rest-connection", "type": "rest", "description": "API for managing blog posts.", "options": { "headers": { "Authorization": "Bearer YOUR_ACCESS_TOKEN" }, "endpoints": [ "https://api.example.com/posts", { "url": "https://api.example.com/posts/:id", "description": "Get a specific post by ID", "method": "GET" }, { "url": "https://api.example.com/search", "description": "Find posts by title or content", "method": "GET", "search": { "query": "search_term" } } ] } } ``` ``` -------------------------------- ### MySQL Data Source Implementation Source: https://context7.com/thecolorred/data-store-mcp/llms.txt A complete MySQL database driver implementing SqlDataSource. It includes connection pooling, query execution for SELECT, INSERT, and schema operations. Handles connection errors and provides methods for connecting, executing queries, and closing the connection. ```typescript import mysql, { type Connection } from 'mysql2/promise'; import { SqlDataSource, type DatabasePayloadBase } from '../../database-source.js'; export class MySQL extends SqlDataSource { private connection?: Connection; async connect(): Promise { const opts = { ...this.connectionConfig.options }; if (!opts.connectTimeout) opts.connectTimeout = 10000; this.connection = await mysql.createConnection(opts); this.connection.on('error', (err) => { console.error('MySQL connection error:', err?.message); }); } async select(): Promise { if (!this.isSelect()) throw new Error('Not a SELECT statement'); if (!this.payload.sql) throw new Error('SQL is required'); const [rows] = await this.connection?.query( this.payload.sql, this.payload.params ) ?? []; return rows; } async insert(): Promise { if (!this.isInsert()) throw new Error('Not an INSERT statement'); const [result] = await this.connection?.execute( this.payload.sql, this.payload.params ) ?? []; return result; } async showSchema(): Promise { if (this.payload.tableName) { const [rows] = await this.connection?.query( 'SHOW CREATE TABLE ??', [this.payload.tableName] ) ?? []; return rows; } // Get all tables, procedures, and functions const [tables] = await this.connection?.query('SHOW TABLES') ?? []; const tableSchemas = await Promise.all( tables.map(async (table) => { const tableName = Object.values(table)[0]; const [schema] = await this.connection?.query( 'SHOW CREATE TABLE ??', [tableName] ) ?? []; return { tableName, schema }; }) ); return tableSchemas; } async close(): Promise { if (!this.connection) return; await this.safeClose( async () => await this.connection?.end(), () => this.connection?.destroy(), 2000 ); } } ``` -------------------------------- ### GraphQL Operations Source: https://github.com/thecolorred/data-store-mcp/blob/main/src/docs/connections.md Guidelines for executing GraphQL queries, including the structure for the payload and handling dynamic values. ```APIDOC ## GraphQL Operations ### Description When executing a graphql query, you should provide a `payload` key containing a JSON object with a `query` key and optionally a `variables` key. When a dynamic value is provided, you MUST add it to the variables property, and not pass it directly in the query string for security reasons. ### Method POST ### Endpoint /graphql ### Parameters #### Request Body - **payload** (object) - Required - Contains the GraphQL query and variables. - **query** (string) - Required - The GraphQL query string. - **variables** (object) - Optional - A JSON object containing variables for the query. ### Request Example ```json { "payload": { "query": "query GetUser($id: ID!) { user(id: $id) { name email } }", "variables": { "id": "123" } } } ``` ### Response #### Success Response (200) - **data** (object) - The result of the GraphQL query. - **errors** (array) - An array of errors, if any occurred during query execution. #### Response Example ```json { "data": { "user": { "name": "John Doe", "email": "john.doe@example.com" } } } ``` ``` -------------------------------- ### SQL Database Operations Source: https://github.com/thecolorred/data-store-mcp/blob/main/src/docs/connections.md Perform SQL queries using SELECT, INSERT, UPDATE, DELETE, or mutation tools. Ensure you provide the correct SQL query string. ```APIDOC ## SQL Database Operations ### Description Execute SQL queries against the database using the `select`, `insert`, `update`, or `delete` tools. For other mutations, use the `mutation` tool. Ensure the `sql` key contains a valid SQL query string. ### Tool Usage - `SELECT` queries: Use the `#select` tool. - `INSERT` queries: Use the `#insert` tool. - `UPDATE` queries: Use the `#update` tool. - `DELETE` queries: Use the `#delete` tool. - All other queries: Use the `#mutation` tool. ### Parameters #### Request Body - **sql** (string) - Required - The SQL query string to execute. ``` -------------------------------- ### GraphQL Data Source Implementation in TypeScript Source: https://context7.com/thecolorred/data-store-mcp/llms.txt Implements a GraphQL client supporting queries and mutations, with introspection capabilities. It requires a GraphQL endpoint URL and allows passing query variables and custom headers. Dependencies include the 'graphql' library for parsing queries. ```typescript import { getIntrospectionQuery, parse } from 'graphql'; import { HttpDataSource } from '../../database-source.js'; export interface GraphQLPayload { query: string; variables?: Record; headers?: Record; } export class GraphQL

extends HttpDataSource

{ async select(): Promise { if (!this.isSelect()) throw new Error('Query must be a GraphQL query operation'); return this.#buildAndSendRequest(); } async mutation(): Promise { if (!this.isMutation()) throw new Error('Query must be a GraphQL mutation operation'); return this.#buildAndSendRequest(); } async showSchema(): Promise { const query = getIntrospectionQuery(); return this.makeHttpRequest({ endpoint: this.connectionConfig.options.url, method: 'POST', headers: { ...this.connectionConfig.options.headers, 'Content-Type': 'application/json', }, body: JSON.stringify({ query }), }); } #buildAndSendRequest() { return this.makeHttpRequest({ ...this.payload, body: { query: this.payload.query, variables: this.payload.variables }, endpoint: this.connectionConfig.options.url, method: 'POST', headers: { ...this.connectionConfig.options.headers, ...this.payload.headers, 'Content-Type': 'application/json', }, }); } isSelect(): boolean { const parsed = parse(this.payload.query); return parsed.definitions.every( i => i.kind === 'OperationDefinition' && i.operation === 'query' ); } isMutation(): boolean { const parsed = parse(this.payload.query); return parsed.definitions.some( i => i.kind === 'OperationDefinition' && i.operation === 'mutation' ); } } // Example GraphQL usage { "connectionId": "my-graphql", "payload": { "query": "query GetPosts($limit: Int!) { posts(limit: $limit) { id title author { name } } }", "variables": { "limit": 10 } } } ``` -------------------------------- ### REST API Call Configuration Source: https://github.com/thecolorred/data-store-mcp/blob/main/src/docs/connections.md Configure REST API calls with 'endpoint', optional 'payload', 'method', and 'headers'. URL parameters can be constructed using 'key=value' pairs. ```json { "endpoint": "/users?id=123", "method": "POST", "payload": { "name": "John Doe" }, "headers": { "Content-Type": "application/json" } } ``` -------------------------------- ### Schema Tool API Source: https://context7.com/thecolorred/data-store-mcp/llms.txt Retrieves database schema information for tables, collections, or entire data stores. It can fetch schema for a specific table or list all tables within a data store. ```APIDOC ## POST /tools/schema ### Description Retrieves database schema information for tables, collections, or entire data stores. ### Method POST ### Endpoint /tools/schema ### Parameters #### Request Body - **connectionId** (string) - Required - The ID of the data source connection. - **payload** (object | string) - Optional - Specifies the schema to retrieve. Can be an object with `tableName` or an empty object to get all tables. ### Request Example ```json { "connectionId": "my-mysql-connection", "payload": { "tableName": "users" } } ``` ### Response #### Success Response (200) - **result** (string) - The schema information, typically a CREATE TABLE statement or an array of table names. #### Response Example ```json "CREATE TABLE users (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), email VARCHAR(255));" ``` ``` -------------------------------- ### GraphQL Query Execution Source: https://github.com/thecolorred/data-store-mcp/blob/main/src/docs/connections.md Execute GraphQL queries by providing a 'payload' object containing 'query' and optionally 'variables'. Dynamic values should be passed in 'variables' for security. ```json { "query": "query GetUser($id: ID!) { user(id: $id) { name email } }", "variables": { "id": "123" } } ``` -------------------------------- ### Update Tool API Source: https://context7.com/thecolorred/data-store-mcp/llms.txt Executes UPDATE statements on databases or PUT requests on HTTP APIs. Allows for parameterized updates in SQL and specifying request details for API updates. ```APIDOC ## POST /tools/update ### Description Executes UPDATE statements on databases or PUT requests on HTTP APIs. ### Method POST ### Endpoint /tools/update ### Parameters #### Request Body - **connectionId** (string) - Required - The ID of the data source connection. - **payload** (object | string) - Required - The update details. For SQL, it includes `sql` and optional `params`. For HTTP, it includes `endpoint`, `method` (defaults to PUT), and optional `headers` and `body`. ### Request Example ```json { "connectionId": "my-postgres", "payload": { "sql": "UPDATE posts SET title = $1, updated_at = NOW() WHERE id = $2", "params": ["Updated Title", 15] } } ``` ### Response #### Success Response (200) - **result** (object) - Details of the update operation, such as `affectedRows` and `changedRows`. #### Response Example ```json { "affectedRows": 1, "changedRows": 1 } ``` ``` -------------------------------- ### MongoDB Data Source Implementation in TypeScript Source: https://context7.com/thecolorred/data-store-mcp/llms.txt This TypeScript class `MongoDB` extends `NoSqlDataSource` to provide specific implementations for MongoDB operations. It handles connection, selecting, inserting, updating, deleting documents, and retrieving schema information. It requires a `mongodb` client and configuration for connection. ```typescript import mongodb from 'mongodb'; import { NoSqlDataSource } from '../../database-source.js'; export interface MongoPayload { method: 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE' | 'DELETE_TABLE'; tableName: string; filter: { [key: string]: any }; value?: { [key: string]: any } | { [key: string]: any }[]; } export class MongoDB

extends NoSqlDataSource

{ client?: mongodb.MongoClient; db?: mongodb.Db; async connect(): Promise { const url = this.connectionConfig.options.url ?? ''; const opts = { ...this.connectionConfig.options.options }; if (!opts.serverSelectionTimeoutMS) opts.serverSelectionTimeoutMS = 10000; if (!opts.connectTimeoutMS) opts.connectTimeoutMS = 10000; this.client = await mongodb.MongoClient.connect(url, opts); this.db = this.client.db(); } async select(): Promise { if (!this.db) throw new Error('Database not found'); if (!this.payload.tableName) throw new Error('tableName is required'); if (!this.payload.filter) throw new Error('filter is required'); const collection = this.db.collection(this.payload.tableName); return await collection.find(this.payload.filter).toArray(); } async insert(): Promise { if (!this.db) throw new Error('Database not found'); if (!this.payload.value) throw new Error('value is required'); const collection = this.db.collection(this.payload.tableName); if (Array.isArray(this.payload.value)) { return collection.insertMany(this.payload.value); } return collection.insertOne(this.payload.value); } async update(): Promise { if (!this.db) throw new Error('Database not found'); if (!this.payload.filter || !this.payload.value) { throw new Error('filter and value are required'); } const collection = this.db.collection(this.payload.tableName); return collection.updateMany(this.payload.filter, this.payload.value); } async delete(): Promise { const collection = this.db.collection(this.payload.tableName); if (Array.isArray(this.payload.filter)) { return collection.deleteMany({ $or: this.payload.filter }); } return collection.deleteMany(this.payload.filter); } async showSchema(): Promise { if (this.payload?.tableName) { return { tableName: this.payload.tableName, indexInfo: await this.db?.collection(this.payload.tableName).indexInformation(), indexes: await this.db?.collection(this.payload.tableName).indexes(), }; } const collections = await this.db?.listCollections().toArray() ?? []; const info = []; for (const collection of collections) { info.push({ tableName: collection.name, indexesInfo: await this.db?.collection(collection.name).indexInformation(), indexes: await this.db?.collection(collection.name).indexes(), }); } return { info }; } } ``` -------------------------------- ### Execute Unrestricted Database Mutations Source: https://context7.com/thecolorred/data-store-mcp/llms.txt The 'mutation' tool allows execution of any type of query on databases, including schema modifications and complex operations, without restrictions. It requires a connection ID and a payload. Permissions are checked before executing the mutation. Returns the result of the mutation. ```typescript server.tool( 'mutation', 'Allows execution of any type of query without restrictions', { connectionId: z.string(), payload: z.union([z.record(z.any()), z.string()]) }, async request => { const { source } = await getSource(request, await getFolders()); if (!isAllowed(source.connectionConfig, 'mutation')) { throw new Error('Mutation tool is not allowed for this connection'); } const result = await source.mutation(); source.close(); return returnText(result); } ); // Example: Create table in MySQL { "connectionId": "my-mysql-connection", "payload": { "sql": "CREATE TABLE products (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255), price DECIMAL(10,2))" } } // Example: GraphQL mutation { "connectionId": "my-graphql", "payload": { "query": "mutation CreatePost($title: String!, $content: String!) { createPost(title: $title, content: $content) { id title createdAt } }", "variables": { "title": "New Post", "content": "Post content here" } } } ``` -------------------------------- ### Retrieve Database Schema Information (TypeScript) Source: https://context7.com/thecolorred/data-store-mcp/llms.txt The schema tool retrieves database schema information for tables, collections, or entire data stores. It requires a connection ID and an optional payload specifying the table name. It returns the schema definition or a list of all tables. ```typescript server.tool( 'schema', 'Lists the schema of a specific table or all tables', { connectionId: z.string(), payload: z.union([z.record(z.any()), z.string()]).optional() }, async request => { const { source } = await getSource(request, await getFolders()); if (!isAllowed(source.connectionConfig, 'schema')) { throw new Error('Schema tool is not allowed for this connection'); } const result = await source.showSchema(); source.close(); return returnText(result); } ); // Example usage with MySQL - get specific table schema { "connectionId": "my-mysql-connection", "payload": { "tableName": "users" } } // Returns: CREATE TABLE statement with columns and indexes // Example usage - get all tables { "connectionId": "my-mysql-connection", "payload": {} } // Returns: Array of all tables, procedures, and functions with their schemas ``` -------------------------------- ### Describe Data Source Payload Structure (TypeScript) Source: https://context7.com/thecolorred/data-store-mcp/llms.txt Registers an MCP tool named 'payload' that returns the required payload structure for a specified data source connection. It retrieves connection details and uses the source's describePayload() method to generate the structure. ```typescript // MCP Tool that returns structured payload information server.tool( 'payload', 'Returns payload structure for the specified connection', { connectionId: z.string() }, async request => { const { source } = await getSource(request, await getFolders(), false); const payload = source.describePayload(); source.close(); return returnText( 'The following is the payload information for the data source:', payload ); } ); // Example MySQL payload description { sql: z.string().describe('Required SQL query to execute'), params: z.record(z.any()).optional().describe('Optional parameters for the SQL query'), tableName: z.string().optional().describe('Optional table name for the SQL query') } // Example REST API payload description { endpoint: z.string().url().describe('The URL endpoint to call'), method: z.enum(['GET', 'POST', 'PUT', 'DELETE']).optional(), headers: z.record(z.string()).optional(), body: z.union([z.string(), z.object({})]).optional() } ``` -------------------------------- ### Amazon AWS S3 Operations Source: https://github.com/thecolorred/data-store-mcp/blob/main/src/docs/connections.md Details on how to perform operations on Amazon AWS S3, including supported methods and required parameters. ```APIDOC ## Amazon AWS S3 Operations ### Description When executing an Amazon AWS S3 operation, you should provide a `payload` key containing a JSON object with details about the operation, bucket, key, and source information. ### Method GET | SELECT | INSERT | UPDATE | DELETE ### Endpoint N/A (Operations are performed via specific tools) ### Parameters #### Request Body - **payload** (object) - Required - Contains parameters for the S3 operation. - **method** (string) - Required - The HTTP method to use (`GET`, `SELECT`, `INSERT`, `UPDATE`, `DELETE`). - **bucket** (string) - Optional - The name of the S3 bucket. - **key** (string) - Required for `SELECT`, `INSERT`, `UPDATE`, `DELETE` - The path to the object in the S3 bucket. - **maxResults** (integer) - Optional - Limits the number of results returned (defaults to 100, used with `#schema` tool). - **sourceType** (string) - Required for `INSERT`, `UPDATE` - Type of the source data (`path` or `raw`). - **sourceValue** (string) - Required for `INSERT`, `UPDATE` - The filesystem path or raw content of the data. ### Request Example (GET) ```json { "payload": { "method": "GET", "bucket": "my-bucket", "key": "path/to/object.txt" } } ``` ### Request Example (INSERT) ```json { "payload": { "method": "INSERT", "bucket": "my-bucket", "key": "path/to/new_object.txt", "sourceType": "raw", "sourceValue": "This is the content of the file." } } ``` ### Response #### Success Response (200) - The response content depends on the `method` used. For `GET` and `SELECT`, it will be the object content or a list of objects. For `INSERT`, `UPDATE`, `DELETE`, it may be a success confirmation. #### Response Example (GET) ```json "File content here." ``` ``` -------------------------------- ### Perform MongoDB Operations (SELECT, INSERT, UPDATE, DELETE) Source: https://github.com/thecolorred/data-store-mcp/blob/main/src/docs/connections.md Execute MongoDB queries by providing a 'payload' object. This object includes 'method', 'tableName', and optionally 'filter' and 'value'. MongoDB automatically creates collections for inserts if they don't exist. ```json { "payload": { "method": "SELECT", "tableName": "collection_name", "filter": { "key": "value" } } } { "payload": { "method": "INSERT", "tableName": "collection_name", "value": [{ "key": "value1" }, { "key": "value2" }] } } { "payload": { "method": "UPDATE", "tableName": "collection_name", "filter": { "key": "value" }, "value": { "key": "new_value" } } } { "payload": { "method": "DELETE", "tableName": "collection_name", "filter": { "key": "value" } } } ``` -------------------------------- ### Execute DELETE Statements and Requests Source: https://context7.com/thecolorred/data-store-mcp/llms.txt The 'delete' tool executes DELETE statements on SQL databases or DELETE requests on HTTP APIs. It requires a connection ID and a payload which can be a record or a string. It validates permissions and checks if the operation is a DELETE statement before execution. Returns affected rows or a confirmation message. ```typescript server.tool( 'delete', 'Runs a delete query on the data source', { connectionId: z.string(), payload: z.union([z.record(z.any()), z.string()]) }, async request => { const { source } = await getSource(request, await getFolders()); if (!isAllowed(source.connectionConfig, 'delete')) { throw new Error('Delete tool is not allowed for this connection'); } if (source instanceof SqlDataSource && !source.isDelete()) { return returnText('The provided SQL query is not a DELETE statement.'); } const result = await source.delete(); source.close(); return returnText(result); } ); // Example: SQLite delete { "connectionId": "my-sqlite", "payload": { "sql": "DELETE FROM users WHERE last_login < ?", "params": ["2023-01-01"] } } // Returns: { affectedRows: 12 } // Example: MongoDB delete { "connectionId": "my-mongodb", "payload": { "method": "DELETE", "tableName": "users", "filter": { "status": "inactive", "createdAt": { "$lt": "2023-01-01" } } } } ``` -------------------------------- ### REST API Data Source Implementation in TypeScript Source: https://context7.com/thecolorred/data-store-mcp/llms.txt Implements a REST API client supporting all CRUD operations (SELECT, INSERT, UPDATE, DELETE). It requires an endpoint and optionally accepts custom methods and headers. Dependencies include the HttpDataSource and HttpPayloadBase types. ```typescript import { HttpDataSource, type HttpPayloadBase } from '../../database-source.js'; export class Rest

extends HttpDataSource

{ async select(): Promise { if (!this.isSelect()) throw new Error('Method must be GET'); return this.#buildAndSendRequest(); } async insert(): Promise { if (!this.isInsert()) throw new Error('Method must be POST'); if (this.payload.method && this.payload.method !== 'POST') { throw new Error('Method must be POST for insert operations'); } return this.#buildAndSendRequest(); } async update(): Promise { if (!this.isUpdate()) throw new Error('Method must be PUT'); return this.#buildAndSendRequest(); } async delete(): Promise { if (!this.isDelete()) throw new Error('Method must be DELETE'); return this.#buildAndSendRequest(); } #buildAndSendRequest(): Promise { if (!this.payload.endpoint) { throw new Error('An endpoint key is required for REST operations'); } return this.makeHttpRequest({ ...this.payload, endpoint: this.payload.endpoint, method: this.payload.method ?? 'GET', headers: { ...this.connectionConfig.options.headers, ...this.payload.headers, }, }); } connect(): Promise { return Promise.resolve(); } close(): Promise { return this.safeClose(() => Promise.resolve()); } } // Example REST connection configuration { "id": "my-rest-api", "type": "rest", "description": "Blog API endpoints", "options": { "headers": { "Authorization": "Bearer YOUR_TOKEN", "Content-Type": "application/json" }, "endpoints": [ "https://api.example.com/posts", { "url": "https://api.example.com/posts/:id", "description": "Get specific post by ID" }, { "url": "https://api.example.com/search", "description": "Search posts", "search": { "query": "Search term" } } ] } } ```