-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitmcp_integration.py
More file actions
153 lines (129 loc) · 5.23 KB
/
gitmcp_integration.py
File metadata and controls
153 lines (129 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
"""
GitMCP Integration for StrandsAgents
Demonstrates how to use MCP (Model Context Protocol) for Git operations
"""
import asyncio
import json
from typing import Dict, List, Optional
class GitMCPClient:
"""Simple MCP client for Git operations"""
def __init__(self, server_path: str = "git"):
self.server_path = server_path
self.connected = False
async def connect(self):
"""Connect to GitMCP server"""
# In a real implementation, this would establish MCP connection
self.connected = True
print("Connected to GitMCP server")
async def list_tools(self) -> List[Dict]:
"""List available Git tools"""
if not self.connected:
await self.connect()
# Mock tools that GitMCP typically provides
return [
{"name": "git_status", "description": "Get repository status"},
{"name": "git_log", "description": "Get commit history"},
{"name": "git_diff", "description": "Show changes"},
{"name": "git_branch", "description": "List/create branches"},
{"name": "git_commit", "description": "Create commits"},
{"name": "git_push", "description": "Push changes"},
{"name": "git_pull", "description": "Pull changes"}
]
async def git_status(self, repo_path: str = ".") -> Dict:
"""Get Git status"""
# Mock implementation - in real use, this would call MCP
return {
"branch": "main",
"modified": ["context7_info.py"],
"untracked": ["gitmcp_integration.py"],
"staged": [],
"clean": False
}
async def git_log(self, repo_path: str = ".", limit: int = 10) -> List[Dict]:
"""Get commit history"""
# Mock implementation
return [
{
"hash": "abc123",
"message": "Fix GitHub API requests",
"author": "developer",
"date": "2024-01-15T10:30:00Z"
}
]
async def git_diff(self, repo_path: str = ".", file_path: Optional[str] = None) -> str:
"""Show Git diff"""
# Mock implementation
return """
diff --git a/context7_info.py b/context7_info.py
index 1234567..abcdefg 100644
--- a/context7_info.py
+++ b/context7_info.py
@@ -1,10 +1,15 @@
import requests
import json
import base64
+
+def get_repo_info(repo_url):
+ \"\"\"Get repository information with error handling\"\"\"
"""
class StrandsGitIntegration:
"""Integration between StrandsAgents and GitMCP"""
def __init__(self):
self.git_client = GitMCPClient()
self.project_path = "m:/strandsagents"
async def initialize(self):
"""Initialize Git integration"""
await self.git_client.connect()
tools = await self.git_client.list_tools()
print(f"Available Git tools: {[t['name'] for t in tools]}")
async def get_project_status(self) -> Dict:
"""Get comprehensive project status"""
status = await self.git_client.git_status(self.project_path)
log = await self.git_client.git_log(self.project_path, limit=5)
return {
"repository_status": status,
"recent_commits": log,
"needs_commit": len(status["modified"]) > 0 or len(status["untracked"]) > 0
}
async def analyze_changes(self) -> Dict:
"""Analyze current changes for agent context"""
diff = await self.git_client.git_diff(self.project_path)
status = await self.git_client.git_status(self.project_path)
return {
"changed_files": status["modified"] + status["untracked"],
"diff_summary": diff[:500] + "..." if len(diff) > 500 else diff,
"change_type": self._classify_changes(status)
}
def _classify_changes(self, status: Dict) -> str:
"""Classify the type of changes"""
modified = status["modified"]
untracked = status["untracked"]
if any("test" in f for f in modified + untracked):
return "testing"
elif any(f.endswith(".py") for f in modified + untracked):
return "code_changes"
elif any(f.endswith(".md") for f in modified + untracked):
return "documentation"
else:
return "general"
async def demo_gitmcp_integration():
"""Demonstrate GitMCP integration"""
print("=== StrandsAgents GitMCP Integration Demo ===\n")
# Initialize integration
git_integration = StrandsGitIntegration()
await git_integration.initialize()
# Get project status
print("\n1. Project Status:")
status = await git_integration.get_project_status()
print(json.dumps(status, indent=2))
# Analyze changes
print("\n2. Change Analysis:")
changes = await git_integration.analyze_changes()
print(json.dumps(changes, indent=2))
# Show how this integrates with your graph system
print("\n3. Graph System Integration:")
print("- Changes can be stored as nodes in your graph system")
print("- Commit history becomes part of project memory")
print("- Agent decisions can be tracked with Git context")
if __name__ == "__main__":
asyncio.run(demo_gitmcp_integration())