Skip to content

Commit ef58e67

Browse files
authored
Add CrewAI Integration Example (#56)
* CrewAI example * feat: add CrewAI integration example * Bump pydantic
1 parent c5afd70 commit ef58e67

File tree

3 files changed

+109
-1
lines changed

3 files changed

+109
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 0.1.7-dev0
2+
3+
### Enhancements
4+
- Added example how to configure MCP server in CrewAI framework
5+
6+
### Fixes
7+
18
## 0.1.6
29

310
### Enhancements

example_clients/crew_ai_agent.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/usr/bin/env python3
2+
# /// script
3+
# dependencies = [
4+
# "crewai>=0.11.0",
5+
# "crewai-tools[mcp]>=0.0.5",
6+
# "pydantic>=2.11.0",
7+
# "python-dotenv>=1.0.0",
8+
# ]
9+
# ///
10+
11+
"""
12+
Example script demonstrating how to use CrewAI with Unstructured MCP to configure sources.
13+
This script creates a CrewAI agent that connects to the Unstructured MCP server
14+
and configures data sources.
15+
16+
1. Configure UNSTRUCTURED_API_KEY, ANTHROPIC_API_KEY, AWS_KEY, AWS_SECRET keys in .env file
17+
2. Start MCP server with:
18+
```
19+
make sse-server
20+
```
21+
22+
3. Run example with:
23+
```
24+
uv run example_clients/crew_ai_agent.py
25+
```
26+
"""
27+
28+
import os
29+
from typing import Optional
30+
31+
from crewai import LLM, Agent, Crew, Task
32+
from crewai_tools import MCPServerAdapter
33+
from dotenv import load_dotenv
34+
from pydantic import BaseModel, Field
35+
from rich.pretty import pprint
36+
37+
load_dotenv()
38+
39+
40+
class SourceConfigurationResult(BaseModel):
41+
source_id: Optional[str] = Field(
42+
default=None,
43+
description="The ID of the configured data source",
44+
)
45+
source_type: Optional[str] = Field(
46+
default=None,
47+
description="The type of data source configured",
48+
)
49+
source_name: Optional[str] = Field(
50+
default=None,
51+
description="The name of the configured data source",
52+
)
53+
source_config: Optional[dict] = Field(
54+
default=None,
55+
description="The configuration details of the data source",
56+
)
57+
58+
59+
def main():
60+
61+
with MCPServerAdapter(
62+
{"url": os.getenv("MCP_SERVER_URL", "http://127.0.0.1:8080/sse")},
63+
) as tools:
64+
llm = LLM(model="anthropic/claude-3-opus-20240229", temperature=0.7, max_tokens=4096)
65+
66+
agent = Agent(
67+
role="Source Configuration Specialist",
68+
goal="Configure and manage data sources for the MCP server",
69+
backstory="""You are an expert in data source configuration and management.
70+
You specialize in setting up and configuring various types of data sources
71+
including AWS S3, Google Drive, and other storage systems. You ensure
72+
proper configuration and validation of data sources.""",
73+
tools=tools,
74+
llm=llm,
75+
verbose=True,
76+
)
77+
78+
task = Task(
79+
description="""Configure an S3 source with the following specifications:
80+
- Name: MCP-S3-Source
81+
- URI: s3://test/uri
82+
- Recursive: true
83+
Ensure the source is properly configured and return the configuration details.""",
84+
agent=agent,
85+
expected_output="""A result containing:
86+
- source_id: The ID of the configured source
87+
- source_config: The configuration details
88+
- source_name: The name of the configured source
89+
- source_type: The type of data source configured
90+
""",
91+
output_pydantic=SourceConfigurationResult,
92+
)
93+
94+
crew = Crew(agents=[agent], tasks=[task], verbose=True)
95+
96+
result = crew.kickoff()
97+
pprint("Task Result:")
98+
pprint(result.tasks_output[0].pydantic)
99+
100+
101+
if __name__ == "__main__":
102+
main()

uns_mcp/connectors/source/source_tool.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ async def create_source_connector(
2828
type_specific_config: dict[str, Any],
2929
) -> str:
3030
"""Create a source connector based on type.
31-
3231
Args:
3332
ctx: Context object with the request and lifespan context
3433
name: A unique name for this connector

0 commit comments

Comments
 (0)