agent-mcp 0.1.1__py3-none-any.whl → 0.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agent_mcp/__init__.py +16 -0
- agent_mcp/crewai_mcp_adapter.py +281 -0
- agent_mcp/enhanced_mcp_agent.py +601 -0
- agent_mcp/heterogeneous_group_chat.py +424 -0
- agent_mcp/langchain_mcp_adapter.py +325 -0
- agent_mcp/langgraph_mcp_adapter.py +325 -0
- agent_mcp/mcp_agent.py +632 -0
- agent_mcp/mcp_decorator.py +257 -0
- agent_mcp/mcp_langgraph.py +733 -0
- agent_mcp/mcp_transaction.py +97 -0
- agent_mcp/mcp_transport.py +700 -0
- agent_mcp/mcp_transport_enhanced.py +46 -0
- agent_mcp/proxy_agent.py +24 -0
- agent_mcp-0.1.3.dist-info/METADATA +331 -0
- agent_mcp-0.1.3.dist-info/RECORD +18 -0
- agent_mcp-0.1.3.dist-info/top_level.txt +1 -0
- agent_mcp-0.1.1.dist-info/METADATA +0 -474
- agent_mcp-0.1.1.dist-info/RECORD +0 -5
- agent_mcp-0.1.1.dist-info/top_level.txt +0 -1
- {agent_mcp-0.1.1.dist-info → agent_mcp-0.1.3.dist-info}/WHEEL +0 -0
- {agent_mcp-0.1.1.dist-info → agent_mcp-0.1.3.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""
|
|
2
|
+
MCP Transaction Layer - Handles secure, atomic transactions between agents.
|
|
3
|
+
|
|
4
|
+
This module provides transaction management for the Model Context Protocol (MCP),
|
|
5
|
+
ensuring reliable and secure interactions between agents.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import asyncio
|
|
9
|
+
from typing import Dict, Any, Optional
|
|
10
|
+
from enum import Enum
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
import uuid
|
|
13
|
+
|
|
14
|
+
class TransactionStatus(Enum):
|
|
15
|
+
PENDING = "pending"
|
|
16
|
+
COMMITTED = "committed"
|
|
17
|
+
ROLLED_BACK = "rolled_back"
|
|
18
|
+
FAILED = "failed"
|
|
19
|
+
|
|
20
|
+
@dataclass
|
|
21
|
+
class TransactionMetadata:
|
|
22
|
+
transaction_id: str
|
|
23
|
+
sender: str
|
|
24
|
+
receiver: str
|
|
25
|
+
timestamp: float
|
|
26
|
+
value: Optional[float] = None
|
|
27
|
+
payment_info: Optional[Dict] = None
|
|
28
|
+
|
|
29
|
+
class MCPTransaction:
|
|
30
|
+
"""Handles atomic transactions between agents"""
|
|
31
|
+
|
|
32
|
+
def __init__(self):
|
|
33
|
+
self.pending_transactions: Dict[str, TransactionMetadata] = {}
|
|
34
|
+
self.completed_transactions: Dict[str, TransactionMetadata] = {}
|
|
35
|
+
|
|
36
|
+
async def begin_transaction(
|
|
37
|
+
self,
|
|
38
|
+
sender: str,
|
|
39
|
+
receiver: str,
|
|
40
|
+
metadata: Dict[str, Any]
|
|
41
|
+
) -> str:
|
|
42
|
+
"""Start a new transaction"""
|
|
43
|
+
transaction_id = str(uuid.uuid4())
|
|
44
|
+
self.pending_transactions[transaction_id] = TransactionMetadata(
|
|
45
|
+
transaction_id=transaction_id,
|
|
46
|
+
sender=sender,
|
|
47
|
+
receiver=receiver,
|
|
48
|
+
timestamp=asyncio.get_event_loop().time(),
|
|
49
|
+
**metadata
|
|
50
|
+
)
|
|
51
|
+
return transaction_id
|
|
52
|
+
|
|
53
|
+
async def commit_transaction(self, transaction_id: str) -> bool:
|
|
54
|
+
"""Commit a transaction"""
|
|
55
|
+
if transaction_id not in self.pending_transactions:
|
|
56
|
+
return False
|
|
57
|
+
|
|
58
|
+
# Move to completed
|
|
59
|
+
transaction = self.pending_transactions.pop(transaction_id)
|
|
60
|
+
self.completed_transactions[transaction_id] = transaction
|
|
61
|
+
return True
|
|
62
|
+
|
|
63
|
+
async def rollback_transaction(self, transaction_id: str) -> bool:
|
|
64
|
+
"""Rollback a transaction"""
|
|
65
|
+
if transaction_id not in self.pending_transactions:
|
|
66
|
+
return False
|
|
67
|
+
|
|
68
|
+
# Remove from pending
|
|
69
|
+
self.pending_transactions.pop(transaction_id)
|
|
70
|
+
return True
|
|
71
|
+
|
|
72
|
+
async def get_transaction_status(self, transaction_id: str) -> TransactionStatus:
|
|
73
|
+
"""Get the current status of a transaction"""
|
|
74
|
+
if transaction_id in self.pending_transactions:
|
|
75
|
+
return TransactionStatus.PENDING
|
|
76
|
+
elif transaction_id in self.completed_transactions:
|
|
77
|
+
return TransactionStatus.COMMITTED
|
|
78
|
+
return TransactionStatus.FAILED
|
|
79
|
+
|
|
80
|
+
class MCPPayment:
|
|
81
|
+
"""Handles payment processing for agent services"""
|
|
82
|
+
|
|
83
|
+
async def process_payment(
|
|
84
|
+
self,
|
|
85
|
+
sender: str,
|
|
86
|
+
receiver: str,
|
|
87
|
+
amount: float,
|
|
88
|
+
currency: str = "USD"
|
|
89
|
+
) -> str:
|
|
90
|
+
"""Process a payment between agents"""
|
|
91
|
+
# TODO: Implement payment processing
|
|
92
|
+
pass
|
|
93
|
+
|
|
94
|
+
async def verify_payment(self, payment_id: str) -> bool:
|
|
95
|
+
"""Verify a payment was successful"""
|
|
96
|
+
# TODO: Implement payment verification
|
|
97
|
+
pass
|