Skip to main content
Glama
cheungxin

JianDaoYun MCP Server

by cheungxin

get_form_fields

Retrieve field definitions from JianDaoYun forms to understand data structure and enable form integration.

Instructions

Get field definitions for a JianDaoYun form

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
appIdYesThe JianDaoYun application ID
appKeyNoThe JianDaoYun application key (API key) (can be provided via JIANDAOYUN_APP_KEY environment variable)
formIdYesThe form ID to query fields for (can be form ID or app ID)

Implementation Reference

  • Core handler function that executes the API call to retrieve form fields from JianDaoYun and transforms the response into FormField array.
    async getFormFields(formId: string): Promise<FormField[]> {
      try {
        const response = await this.axios.post<ApiResponse<{ widgets: any[] }>>('/v5/app/entry/widget/list', {
          app_id: this.config.appId,
          entry_id: formId
        });
    
        // 检查是否有错误响应格式
        if (response.data.code !== undefined && response.data.code !== 0) {
          throw new Error(`Failed to get form fields: ${response.data.msg}`);
        }
    
        // API返回格式: {widgets: [...], sysWidgets: ...}
        const widgets = (response.data as any).widgets || [];
        return this.transformFields(Array.isArray(widgets) ? widgets : []);
      } catch (error) {
        if (axios.isAxiosError(error)) {
          throw new Error(`API request failed: ${error.response?.data?.msg || error.message}`);
        }
        throw error;
      }
    }
  • Helper function to recursively transform API widget data into standardized FormField objects.
    private transformFields(widgets: any[]): FormField[] {
      return widgets.map(widget => {
        const field: FormField = {
          key: widget.name,
          name: widget.label,
          type: this.mapFieldType(widget.type),
          required: widget.required || false
        };
    
        if (widget.type === 'subform' && widget.items) {
          field.subForm = {
            fields: this.transformFields(widget.items)
          };
        }
    
        return field;
      });
    }
  • Helper function to map JianDaoYun API field types to standardized field types.
    private mapFieldType(apiType: string): string {
      const typeMap: { [key: string]: string } = {
        'text': 'text',
        'textarea': 'text',
        'number': 'number',
        'date': 'date',
        'datetime': 'datetime',
        'sn': 'serial_no',
        'address': 'address',
        'location': 'location',
        'image': 'image',
        'file': 'file',
        'single_select': 'select',
        'multiple_select': 'multi_select',
        'checkbox': 'checkbox',
        'radio': 'radio',
        'user': 'user',
        'dept': 'dept',
        'subform': 'subform',
        'formula': 'formula',
        'phone': 'phone'
      };
    
      return typeMap[apiType] || 'text';
    }
  • src/index.ts:248-268 (registration)
    MCP tool registration defining the 'get_form_fields' tool name, description, and input schema.
      name: 'get_form_fields',
      description: 'Get field definitions for a JianDaoYun form',
      inputSchema: {
        type: 'object',
        properties: {
          appId: {
            type: 'string',
            description: 'The JianDaoYun application ID',
          },
          appKey: {
            type: 'string',
            description: 'The JianDaoYun application key (API key) (can be provided via JIANDAOYUN_APP_KEY environment variable)',
          },
          formId: {
            type: 'string',
            description: 'The form ID to query fields for (can be form ID or app ID)',
          },
        },
        required: ['appId', 'formId'],
      },
    },
  • MCP server request handler for executing the get_form_fields tool, including parameter validation, client instantiation, form ID resolution, and response formatting.
    case 'get_form_fields': {
      const { formId } = args as { formId: string };
      const { appId, appKey, baseUrl } = getDefaultParams(args);
      
      // 验证必需参数
      if (!appKey) {
        throw new Error('appKey is required. Please set JIANDAOYUN_APP_KEY in MCP server configuration.');
      }
      if (!appId) {
        throw new Error('appId is required. Please provide it as parameter.');
      }
      
      try {
        // 创建客户端实例
        const jdyClient = new JianDaoYunClient({
          appId,
          appKey,
          baseUrl
        });
        
        const resolved = await resolveFormId(formId, appKey);
        const fields = await jdyClient.getFormFields(resolved.formId);
        
        let responseText = JSON.stringify(fields, null, 2);
        
        // 如果有多个表单建议,添加提示信息
        if (resolved.suggestions && resolved.suggestions.length > 1) {
          responseText = `// 注意: 检测到应用下有多个表单,当前使用第一个表单\n// 可用表单列表:\n${resolved.suggestions.map(s => `// - ${s}`).join('\n')}\n\n${responseText}`;
        }
        
        return {
          content: [
            {
              type: 'text',
              text: responseText,
            },
          ],
        };
      } catch (error) {
        throw createEnhancedError(error, '获取表单字段');
      }
    }
  • TypeScript interface defining the structure of form fields returned by the tool.
    export interface FormField {
      key: string;
      name: string;
      type: string;
      required?: boolean;
      subForm?: {
        fields: FormField[];
      };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool retrieves field definitions, implying a read-only operation, but doesn't cover aspects like authentication requirements (though hinted in the schema), rate limits, error handling, or return format. This leaves significant gaps for a tool with no annotation coverage.

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 a single, direct sentence that efficiently conveys the tool's purpose without unnecessary words. It is appropriately sized and front-loaded, making it easy for an agent to parse quickly.

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 lack of annotations and output schema, the description is incomplete. It doesn't explain what 'field definitions' entail (e.g., structure, data types), how results are returned, or any behavioral traits like pagination or errors. For a tool with no structured output information, this leaves the agent with insufficient context.

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%, with all parameters clearly documented in the input schema. The description adds no additional meaning beyond what the schema provides, such as explaining relationships between parameters or usage nuances. This meets the baseline score of 3 when the schema handles parameter documentation effectively.

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 action ('Get field definitions') and target resource ('for a JianDaoYun form'), which is specific and unambiguous. However, it doesn't explicitly differentiate this tool from sibling tools like 'get_form_data' or 'query_form_data', which might also retrieve form-related information but with different scopes or purposes.

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, such as 'get_form_data' or 'query_form_data'. There's no mention of prerequisites, context, or exclusions, leaving the agent to infer usage based on the tool name alone.

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/cheungxin/jiandaoyun-mcp-server'

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