@vaiftech/mcp 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +19 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {StdioServerTransport}from'@modelcontextprotocol/sdk/server/stdio.js';import {McpServer}from'@modelcontextprotocol/sdk/server/mcp.js';import {z}from'zod';import {readFileSync}from'fs';import {join}from'path';import {homedir}from'os';var P=Object.defineProperty;var
|
|
2
|
+
import {StdioServerTransport}from'@modelcontextprotocol/sdk/server/stdio.js';import {McpServer}from'@modelcontextprotocol/sdk/server/mcp.js';import {z}from'zod';import {readFileSync}from'fs';import {join}from'path';import {homedir}from'os';var P=Object.defineProperty;var C=(r,t,e)=>t in r?P(r,t,{enumerable:true,configurable:true,writable:true,value:e}):r[t]=e;var u=(r,t,e)=>C(r,typeof t!="symbol"?t+"":t,e);var f=class{constructor(t){u(this,"apiUrl");u(this,"projectId");u(this,"apiKey");u(this,"authToken");this.apiUrl=t.apiUrl.replace(/\/+$/,""),this.projectId=t.projectId,this.apiKey=t.apiKey,this.authToken=t.authToken;}async dataPlane(t,e,o){if(!this.apiKey)throw new Error("API key is required for data plane requests. Set --api-key or VAIF_API_KEY.");let n=`${this.apiUrl}${e}`,i={"Content-Type":"application/json","x-vaif-key":this.apiKey},s=await fetch(n,{method:t,headers:i,body:o?JSON.stringify(o):void 0});if(!s.ok){let l=await s.text().catch(()=>"");throw new Error(`Data plane ${t} ${e} failed (${s.status}): ${l}`)}let p=await s.text();if(p)return JSON.parse(p)}async controlPlane(t,e,o){if(!this.authToken)throw new Error("Auth token is required for control plane requests. Set --auth-token or VAIF_AUTH_TOKEN.");let n=`${this.apiUrl}${e}`,i={"Content-Type":"application/json",Authorization:`Bearer ${this.authToken}`},s=await fetch(n,{method:t,headers:i,body:o?JSON.stringify(o):void 0});if(!s.ok){let l=await s.text().catch(()=>"");throw new Error(`Control plane ${t} ${e} failed (${s.status}): ${l}`)}let p=await s.text();if(p)return JSON.parse(p)}};function y(r,t){r.tool("list_tables","List all tables in the VAIF project database. Returns table names and basic metadata.",{},async()=>{try{let o=((await t.controlPlane("GET",`/schema-engine/introspect/${t.projectId}`)).tables||[]).map(n=>n.name);return {content:[{type:"text",text:JSON.stringify(o,null,2)}]}}catch(e){return {content:[{type:"text",text:`Error listing tables: ${e instanceof Error?e.message:String(e)}`}]}}}),r.tool("describe_table","Describe a specific table's columns, types, constraints, and relationships.",{table:z.string().describe("The name of the table to describe")},async({table:e})=>{try{let n=((await t.controlPlane("GET",`/schema-engine/introspect/${t.projectId}`)).tables||[]).find(i=>i.name===e);return n?{content:[{type:"text",text:JSON.stringify(n,null,2)}]}:{content:[{type:"text",text:`Table "${e}" not found. Use list_tables to see available tables.`}]}}catch(o){return {content:[{type:"text",text:`Error describing table: ${o instanceof Error?o.message:String(o)}`}]}}}),r.tool("query_rows","Query rows from a table with optional filtering, sorting, and pagination. Filter operators: eq, neq, gt, lt, gte, lte, in, like, ilike, is.",{table:z.string().describe("The table to query"),filter:z.record(z.string()).optional().describe('Filter conditions as key-value pairs. Use "field" for equality or "field.op" for operators (e.g. "age.gt": "18", "name.like": "%john%")'),limit:z.number().optional().describe("Maximum number of rows to return (default: 50)"),offset:z.number().optional().describe("Number of rows to skip for pagination"),order_by:z.string().optional().describe("Column name to order results by"),order:z.enum(["asc","desc"]).optional().describe("Sort direction (asc or desc)")},async({table:e,filter:o,limit:n,offset:i,order_by:s,order:p})=>{try{let l=new URLSearchParams;if(o)for(let[v,E]of Object.entries(o))l.append(`filter[${v}]`,E);n!==void 0&&l.append("limit",String(n)),i!==void 0&&l.append("offset",String(i)),s&&l.append("order_by",s),p&&l.append("order",p);let m=l.toString(),w=`/generated/${e}${m?`?${m}`:""}`,k=await t.dataPlane("GET",w);return {content:[{type:"text",text:JSON.stringify(k,null,2)}]}}catch(l){return {content:[{type:"text",text:`Error querying rows: ${l instanceof Error?l.message:String(l)}`}]}}}),r.tool("insert_row","Insert a new row into a table. Returns the created row with generated fields (id, timestamps, etc).",{table:z.string().describe("The table to insert into"),data:z.record(z.any()).describe("Column values for the new row")},async({table:e,data:o})=>{try{let n=await t.dataPlane("POST",`/generated/${e}`,o);return {content:[{type:"text",text:JSON.stringify(n,null,2)}]}}catch(n){return {content:[{type:"text",text:`Error inserting row: ${n instanceof Error?n.message:String(n)}`}]}}}),r.tool("update_row","Update an existing row by ID. Returns the updated row.",{table:z.string().describe("The table containing the row"),id:z.string().describe("The ID of the row to update"),data:z.record(z.any()).describe("Column values to update")},async({table:e,id:o,data:n})=>{try{let i=await t.dataPlane("PATCH",`/generated/${e}/${o}`,n);return {content:[{type:"text",text:JSON.stringify(i,null,2)}]}}catch(i){return {content:[{type:"text",text:`Error updating row: ${i instanceof Error?i.message:String(i)}`}]}}}),r.tool("delete_row","Delete a row by ID. Returns confirmation of the deletion.",{table:z.string().describe("The table containing the row"),id:z.string().describe("The ID of the row to delete")},async({table:e,id:o})=>{try{let n=await t.dataPlane("DELETE",`/generated/${e}/${o}`);return {content:[{type:"text",text:JSON.stringify(n??{success:!0,deleted:o},null,2)}]}}catch(n){return {content:[{type:"text",text:`Error deleting row: ${n instanceof Error?n.message:String(n)}`}]}}});}function h(r,t){r.tool("list_buckets","List all storage buckets in the VAIF project.",{},async()=>{try{let e=await t.controlPlane("GET",`/storage/buckets?projectId=${t.projectId}`);return {content:[{type:"text",text:JSON.stringify(e,null,2)}]}}catch(e){return {content:[{type:"text",text:`Error listing buckets: ${e instanceof Error?e.message:String(e)}`}]}}}),r.tool("list_files","List files in a storage bucket, optionally filtered by path prefix.",{bucket:z.string().describe("The bucket name"),path:z.string().optional().describe("Path prefix to filter files (e.g. 'images/avatars/')")},async({bucket:e,path:o})=>{try{let n=new URLSearchParams;o&&n.append("prefix",o);let i=n.toString(),s=`/storage/files/${t.projectId}/${e}${i?`?${i}`:""}`,p=await t.controlPlane("GET",s);return {content:[{type:"text",text:JSON.stringify(p,null,2)}]}}catch(n){return {content:[{type:"text",text:`Error listing files: ${n instanceof Error?n.message:String(n)}`}]}}}),r.tool("get_signed_url","Generate a signed download URL for a file in storage. The URL is temporary and expires after the specified duration.",{bucket:z.string().describe("The bucket name"),path:z.string().describe("Path to the file within the bucket"),expiresIn:z.number().optional().describe("URL expiration time in seconds (default: 3600)")},async({bucket:e,path:o,expiresIn:n})=>{try{let i=await t.controlPlane("POST","/storage/download",{bucket:e,path:o,expiresIn:n});return {content:[{type:"text",text:JSON.stringify(i,null,2)}]}}catch(i){return {content:[{type:"text",text:`Error getting signed URL: ${i instanceof Error?i.message:String(i)}`}]}}});}function b(r,t){r.tool("list_functions","List all serverless functions deployed in the VAIF project.",{},async()=>{try{let e=await t.controlPlane("GET",`/functions/project/${t.projectId}`);return {content:[{type:"text",text:JSON.stringify(e,null,2)}]}}catch(e){return {content:[{type:"text",text:`Error listing functions: ${e instanceof Error?e.message:String(e)}`}]}}}),r.tool("invoke_function","Invoke a serverless function by ID with an optional JSON payload. Returns the function's response.",{functionId:z.string().describe("The ID of the function to invoke"),payload:z.record(z.any()).optional().describe("JSON payload to pass to the function")},async({functionId:e,payload:o})=>{try{let n=await t.controlPlane("POST",`/functions/${e}/invoke`,o??{});return {content:[{type:"text",text:JSON.stringify(n,null,2)}]}}catch(n){return {content:[{type:"text",text:`Error invoking function: ${n instanceof Error?n.message:String(n)}`}]}}});}function x(r,t){r.tool("get_schema","Get the full database schema for the VAIF project, including all tables, columns, types, constraints, and relationships.",{},async()=>{try{let e=await t.controlPlane("GET",`/schema-engine/introspect/${t.projectId}`);return {content:[{type:"text",text:JSON.stringify(e,null,2)}]}}catch(e){return {content:[{type:"text",text:`Error getting schema: ${e instanceof Error?e.message:String(e)}`}]}}}),r.tool("create_tables",`Create or update database tables in the VAIF project. Accepts a full schema definition with tables, columns, indexes, and foreign keys. This is a declarative operation \u2014 provide the desired end-state and VAIF will diff and apply changes.
|
|
3
|
+
|
|
4
|
+
Valid column types: uuid, text, varchar, string, int, integer, bigint, boolean, bool, jsonb, json, timestamptz, timestamp, date, numeric, decimal, float, double, text[], integer[]
|
|
5
|
+
|
|
6
|
+
Example:
|
|
7
|
+
{
|
|
8
|
+
"tables": [{
|
|
9
|
+
"name": "posts",
|
|
10
|
+
"columns": [
|
|
11
|
+
{ "name": "id", "type": "uuid", "primaryKey": true, "default": "gen_random_uuid()" },
|
|
12
|
+
{ "name": "title", "type": "text", "nullable": false },
|
|
13
|
+
{ "name": "body", "type": "text" },
|
|
14
|
+
{ "name": "author_id", "type": "uuid", "references": { "table": "users", "column": "id", "onDelete": "CASCADE" } },
|
|
15
|
+
{ "name": "created_at", "type": "timestamptz", "default": "now()" }
|
|
16
|
+
],
|
|
17
|
+
"indexes": [{ "name": "idx_posts_author", "columns": ["author_id"] }]
|
|
18
|
+
}]
|
|
19
|
+
}`,{tables:z.array(z.object({name:z.string().describe("Table name"),columns:z.array(z.object({name:z.string().describe("Column name"),type:z.enum(["uuid","text","varchar","string","int","integer","bigint","boolean","bool","jsonb","json","timestamptz","timestamp","date","numeric","decimal","float","double","text[]","integer[]"]).describe("Column type"),primaryKey:z.boolean().optional().describe("Is primary key"),unique:z.boolean().optional().describe("Has unique constraint"),nullable:z.boolean().optional().describe("Allows NULL (default: true)"),default:z.union([z.string(),z.number(),z.boolean()]).optional().describe("Default value (e.g. 'gen_random_uuid()', 'now()', true)"),references:z.object({table:z.string().describe("Referenced table"),column:z.string().optional().describe("Referenced column (default: id)"),onDelete:z.enum(["CASCADE","RESTRICT","SET NULL","SET DEFAULT","NO ACTION"]).optional(),onUpdate:z.enum(["CASCADE","RESTRICT","SET NULL","SET DEFAULT","NO ACTION"]).optional()}).optional().describe("Foreign key reference")})).describe("Table columns"),indexes:z.array(z.object({name:z.string().describe("Index name"),columns:z.array(z.string()).describe("Indexed columns"),unique:z.boolean().optional().describe("Unique index")})).optional().describe("Table indexes")})).describe("Tables to create or update"),migration_name:z.string().optional().describe("Optional migration name for tracking"),allow_destructive:z.boolean().optional().describe("Allow destructive changes like dropping columns (default: false)")},async({tables:e,migration_name:o,allow_destructive:n})=>{try{let i={schemaVersion:"1.0",tables:e},s=await t.controlPlane("POST","/schema-engine/apply",{projectId:t.projectId,definition:i,migrationName:o,allowDestructive:n??!1});return {content:[{type:"text",text:JSON.stringify(s,null,2)}]}}catch(i){return {content:[{type:"text",text:`Error creating tables: ${i instanceof Error?i.message:String(i)}`}]}}});}function T(r,t){r.resource("schema","vaif://schema",{description:"The full database schema for the connected VAIF project, including tables, columns, types, and relationships.",mimeType:"application/json"},async()=>{let e=await t.controlPlane("GET",`/schema-engine/introspect/${t.projectId}`);return {contents:[{uri:"vaif://schema",mimeType:"application/json",text:JSON.stringify(e,null,2)}]}});}function I(r,t){r.resource("project-info","vaif://project-info",{description:"Project metadata for the connected VAIF project, including name, region, settings, and status.",mimeType:"application/json"},async()=>{let e=await t.controlPlane("GET",`/projects/${t.projectId}`);return {contents:[{uri:"vaif://project-info",mimeType:"application/json",text:JSON.stringify(e,null,2)}]}});}function S(r){let t=new McpServer({name:"vaif-studio",version:"1.0.2"}),e=new f(r);return y(t,e),h(t,e),b(t,e),x(t,e),T(t,e),I(t,e),t}function O(){let r=process.argv.slice(2),t={};for(let e=0;e<r.length;e++){let o=r[e],n=r[e+1];switch(o){case "--api-key":t.apiKey=n,e++;break;case "--project-id":t.projectId=n,e++;break;case "--api-url":t.apiUrl=n,e++;break;case "--auth-token":t.authToken=n,e++;break;case "--help":case "-h":console.error(`
|
|
3
20
|
vaif-mcp \u2014 MCP server for VAIF Studio
|
|
4
21
|
|
|
5
22
|
Usage:
|
|
@@ -21,4 +38,4 @@ Environment variables:
|
|
|
21
38
|
Config files (checked in order):
|
|
22
39
|
./vaif.config.json Local project config
|
|
23
40
|
~/.vaif/auth.json User auth config
|
|
24
|
-
`),process.exit(0);}}return t}function
|
|
41
|
+
`),process.exit(0);}}return t}function j(r){try{let t=readFileSync(r,"utf-8");return JSON.parse(t)}catch{return null}}function F(){let r=O(),t={apiKey:process.env.VAIF_API_KEY,projectId:process.env.VAIF_PROJECT_ID,apiUrl:process.env.VAIF_API_URL,authToken:process.env.VAIF_AUTH_TOKEN},e=j(join(process.cwd(),"vaif.config.json")),o=e?.projectId,n=e?.api?.apiKey,i=j(join(homedir(),".vaif","auth.json")),s=i?.token,p=i?.projectId;return {apiUrl:r.apiUrl||t.apiUrl||"https://api.vaif.studio",projectId:r.projectId||t.projectId||o||p,apiKey:r.apiKey||t.apiKey||n,authToken:r.authToken||t.authToken||s}}async function N(){let r=F();r.projectId||(console.error("Error: Project ID is required. Set --project-id, VAIF_PROJECT_ID, or configure vaif.config.json."),process.exit(1)),!r.apiKey&&!r.authToken&&(console.error("Error: Authentication required. Set --api-key / VAIF_API_KEY or --auth-token / VAIF_AUTH_TOKEN."),process.exit(1)),console.error("VAIF MCP Server v1.0.0"),console.error(` Project: ${r.projectId}`),console.error(` API URL: ${r.apiUrl}`),console.error(` Auth: ${r.apiKey?"API Key":""}${r.apiKey&&r.authToken?" + ":""}${r.authToken?"Auth Token":""}`);let t=S({apiUrl:r.apiUrl,projectId:r.projectId,apiKey:r.apiKey,authToken:r.authToken}),e=new StdioServerTransport;await t.connect(e),console.error("VAIF MCP Server running on stdio");}N().catch(r=>{console.error("Fatal error:",r),process.exit(1);});
|