Agentify 组件库

Agentify 组件库

用户可下载的组件,用于动态创建 MCP 服务器。

快速入门

安装

运行以下命令安装 Agentify Components:

npm install @anvosio/agentify-components

示例:为按钮添加智能配置

使用装饰器(类组件)

import { AgentConfig } from '@anvos/agentify-components';

@AgentConfig({
  type: 'button',
  behavior: { type: 'navigation', href: '/home' },
  label: 'Home Button',
  description: '导航至首页'
})
class HomeButton extends React.Component {
  render() {
    return <button>Home</button>;
  }
}

使用 HOC(函数组件)

import { withAgentConfig } from '@anvos/agentify-components';

export const LoginButton = withAgentConfig({
  type: 'button',
  behavior: { type: 'api', endpoint: '/api/login', method: 'POST' },
  label: 'Login Button',
  description: '通过 API 提交登录表单'
})(() => {
  return <button>Login</button>;
});

生成 MCP 服务器

  1. 创建 generate.ts 文件:
import { generateMCPServer } from '@anvos/agentify-components';
import * as components from './components/ButtonExample';

generateMCPServer(Object.values(components), './mcpServer');
  1. 添加脚本到 package.json
"scripts": {
  "build:mcp": "ts-node ./generate.ts"
}
  1. 运行以下命令生成服务器:
npm run build:mcp