Skip to main content
Glama
6June6
by 6June6

add

Add data to a UniCloud database collection using the MCP protocol. Specify collection name and data object to insert records.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionYes集合名称
dataYes要添加的数据 (object/array)

Implementation Reference

  • MCP 'add' tool handler: extracts collection and data from params, calls addToDatabase, returns formatted success or error response.
    async function handleAddTool(params, dbUrl) {
      const { collection, data } = params;
    
      try {
        const result = await addToDatabase(collection, data, dbUrl);
        return {
          content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
        };
      } catch (error) {
        return {
          content: [{ type: 'text', text: error.message }],
          isError: true,
        };
      }
    }
  • Tool definition object for 'add', including Zod input schema for parameters (collection and data).
    addTool: {
      name: 'add',
      params: {
        collection: z.string().describe('集合名称'),
        data: z.record(z.any()).describe('要添加的数据 (object/array)'),
      },
      handler: (params) => handleAddTool(params, dbServiceUrl),
    },
  • index.js:44-44 (registration)
    Registers the 'add' tool on the MCP server with its name, params schema, and handler.
    server.tool(tools.addTool.name, tools.addTool.params, tools.addTool.handler);
  • Helper function performing the actual database insert: sends POST request to uniCloud DB service with JQL operation 'insert'.
    async function addToDatabase(collection, data, dbUrl = DEFAULT_DB_URL) {
      try {
        const controller = new AbortController();
        const timeoutId = setTimeout(() => controller.abort(), REQUEST_TIMEOUT);
    
        // 使用传入的dbUrl或默认URL
        const targetUrl = dbUrl || DEFAULT_DB_URL;
        // console.log('添加操作使用URL:', targetUrl);
    
        const response = await fetch(targetUrl, {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({
            operation: {
              collection,
              action: 'insert',
              data,
            },
          }),
          signal: controller.signal,
        });
    
        clearTimeout(timeoutId);
        const result = await response.json();
    
        if (result.code !== 0) {
          throw new Error(result.msg || '添加失败');
        }
    
        return result.data;
      } catch (error) {
        if (error.name === 'AbortError') {
          throw new Error(`添加超时: 请求超过${REQUEST_TIMEOUT}毫秒`);
        }
        throw new Error(`添加错误: ${error.message}`);
      }
    }

Tool Definition Quality

Score is being calculated. Check back soon.

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/6June6/uniclouddb-mcp'

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