使用说明
MCP Curl服务器和带有kagent的代理
本指南解释了如何使用kmcp在Kubernetes上部署MCP Curl服务器,并创建一个可以向任何URL发出HTTP请求的AI代理。
目录
概述
MCP Curl Server为AI代理提供了使用类似Curl的接口向任何URL发出HTTP请求的能力。这使代理能够与web服务、API交互,并从互联网获取数据。
能力
这 curl 工具接受以下参数:
| 参数 | 必填 | 说明 |
|---|---|---|
url |
是 | 向其发出请求的URL |
method |
否 | HTTP方法(GET、POST、PUT、DELETE、PATCH、HEAD、OPTIONS)。默认值:GET |
headers |
否 | 包含HTTP标头的对象 |
body |
否 | POST/PUT/PATCH请求的请求正文 |
timeout |
否 | 请求超时(毫秒)(默认值:30000,最大值:300000) |
响应格式
该工具返回结构化响应,其中包含:
{
"status": 200,
"statusText": "OK",
"headers": {
"content-type": "application/json",
"server": "nginx"
},
"body": "{\"result\": \"success\"}"
}
建筑
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ kagent Agent │────▶│ MCP Curl │────▶│ External │
│ (HTTP Client) │ │ Server │ │ APIs/Services │
└─────────────────┘ └──────────────────┘ └─────────────────┘
先决条件
- 安装了kagent和kmcp的Kubernetes集群
kubectl已配置为访问您的群集
第1部分:部署MCP Curl服务器
kubectl apply -f- <<EOF
apiVersion: kagent.dev/v1alpha1
kind: MCPServer
metadata:
name: mcp-curl
namespace: kagent
spec:
deployment:
args:
- '-y'
- '@mcp-get-community/server-curl'
cmd: npx
port: 3000
stdioTransport: {}
transportType: stdio
EOF
验证部署
# Check the MCPServer resource
kubectl get mcpserver -n kagent mcp-curl
# Check the pod is running
kubectl get pods -n kagent -l app.kubernetes.io/name=mcp-curl
# View logs
kubectl logs -n kagent -l app.kubernetes.io/name=mcp-curl
第2部分:部署Curl Agent
kubectl apply -f - <<EOF
apiVersion: kagent.dev/v1alpha2
kind: Agent
metadata:
name: curl-agent
namespace: kagent
spec:
description: An HTTP client agent that can make requests to any URL using curl.
type: Declarative
declarative:
modelConfig: default-model-config
systemMessage: |-
You are an HTTP client agent that helps users make web requests and interact with APIs.
# Capabilities
You can:
- Make GET requests to fetch data from URLs
- Make POST/PUT/PATCH requests to send data to APIs
- Set custom headers (authentication, content-type, etc.)
- Handle JSON and other response formats
# Instructions
- If the user question is unclear, ask for clarification
- Always explain what request you're about to make before executing
- Format JSON responses in a readable way
- Warn users about sending sensitive data over HTTP (non-HTTPS)
- If you don't know how to help, say so clearly
# Response format
- ALWAYS format your response as Markdown
- Display response status, headers, and body clearly
- Parse and format JSON responses for readability
tools:
- type: McpServer
mcpServer:
name: mcp-curl
kind: MCPServer
toolNames:
- curl
a2aConfig:
skills:
- id: http-requests
name: HTTP Requests
description: Make HTTP requests to any URL with custom methods, headers, and body
inputModes:
- text
outputModes:
- text
tags:
- http
- api
- curl
- web
examples:
- "Fetch the contents of https://api.github.com"
- "POST JSON data to an API endpoint"
- "Check if a website is up"
- "Get the headers from a URL"
- "Make an authenticated API request"
EOF
第3部分:测试代理
使用kagent命令行界面
# Simple GET request
kagent invoke --agent curl-agent --task "Fetch https://httpbin.org/get"
# Check a website status
kagent invoke --agent curl-agent --task "Check if https://google.com is responding"
# Get JSON from an API
kagent invoke --agent curl-agent --task "Get the current Bitcoin price from a public API"
使用kagent仪表板
kagent dashboard
引导到 curl-agent 并尝试以下提示:
- “向发出GET请求https://api.github.com"
- “POST{'name':'test'}到https://httpbin.org/post"
- “取回https://httpbin.org/headers并向我显示响应标头”
用例
| 用例 | 示例提示 |
|---|---|
| API测试 | “将JSON有效负载发布到我的API端点” |
| 健康检查 | “检查https://myservice.com/health返回200“ |
| 数据获取 | “从此REST API获取最新数据” |
| Webhook测试 | “将测试Webhook发送到此URL” |
| 标头检查 | “显示此服务器返回的标头” |
| 身份验证 | “使用承载令牌身份验证发出请求” |