-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.py
More file actions
306 lines (272 loc) · 10.4 KB
/
main.py
File metadata and controls
306 lines (272 loc) · 10.4 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#!/usr/bin/env python3
import os
from typing import Dict, Any, Optional
from fastmcp import FastMCP
from pydantic import BaseModel, Field
import httpx
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Initialize MCP server
mcp = FastMCP(
name="Secureframe MCP Server",
instructions="Read-only access to Secureframe compliance platform data"
)
# Configuration
class SecureframeConfig(BaseModel):
"""Secureframe API configuration"""
api_key: str
api_secret: str
base_url: str = "https://api.secureframe.com"
def __init__(self):
super().__init__(
api_key=os.getenv("SECUREFRAME_API_KEY", ""),
api_secret=os.getenv("SECUREFRAME_API_SECRET", ""),
base_url=os.getenv("SECUREFRAME_API_URL", "https://api.secureframe.com")
)
if not self.api_key or not self.api_secret:
raise ValueError(
"SECUREFRAME_API_KEY and SECUREFRAME_API_SECRET environment variables must be set"
)
@property
def headers(self) -> Dict[str, str]:
"""Authorization headers"""
return {
"Authorization": f"{self.api_key} {self.api_secret}",
"Content-Type": "application/json"
}
config = SecureframeConfig()
# Helper functions
async def make_request(
method: str,
endpoint: str,
params: Optional[Dict[str, Any]] = None,
json_data: Optional[Dict[str, Any]] = None
) -> Dict[str, Any]:
"""Make API request to Secureframe"""
url = f"{config.base_url}{endpoint}"
async with httpx.AsyncClient(timeout=30.0) as client:
try:
response = await client.request(
method=method,
url=url,
headers=config.headers,
params=params,
json=json_data
)
response.raise_for_status()
return response.json()
except httpx.HTTPStatusError as e:
return {"error": f"API Error {e.response.status_code}: {e.response.text}"}
except Exception as e:
return {"error": str(e)}
# Controls Tools (read-only)
@mcp.tool
async def list_controls(
page: int = Field(1, description="Page number for pagination"),
per_page: int = Field(100, description="Items per page (default: 100)"),
search_query: Optional[str] = Field(None, description="Lucene search query to filter controls"),
include_relationships: bool = Field(False, description="Include relationship data")
) -> Dict[str, Any]:
"""List security controls with filtering support"""
params = {
"page": page,
"per_page": per_page,
"relationships": include_relationships
}
if search_query:
params["q"] = search_query
if include_relationships:
params["include"] = True
return await make_request("GET", "/controls", params=params)
# Tests Tools (read-only)
@mcp.tool
async def list_tests(
page: int = Field(1, description="Page number for pagination"),
per_page: int = Field(100, description="Items per page (default: 100)"),
search_query: Optional[str] = Field(None, description="Lucene search query to filter tests"),
include_relationships: bool = Field(False, description="Include relationship data")
) -> Dict[str, Any]:
"""List compliance tests with filtering support"""
params = {
"page": page,
"per_page": per_page,
"relationships": include_relationships
}
if search_query:
params["q"] = search_query
if include_relationships:
params["include"] = True
return await make_request("GET", "/tests", params=params)
# Users Tools (read-only)
@mcp.tool
async def list_users(
page: int = Field(1, description="Page number for pagination"),
per_page: int = Field(100, description="Items per page (default: 100)"),
search_query: Optional[str] = Field(None, description="Lucene search query to filter users"),
include_relationships: bool = Field(False, description="Include relationship data")
) -> Dict[str, Any]:
"""List users with filtering support"""
params = {
"page": page,
"per_page": per_page,
"relationships": include_relationships
}
if search_query:
params["q"] = search_query
if include_relationships:
params["include"] = True
return await make_request("GET", "/users", params=params)
# Devices Tools (read-only)
@mcp.tool
async def list_devices(
page: int = Field(1, description="Page number for pagination"),
per_page: int = Field(100, description="Items per page (default: 100)"),
search_query: Optional[str] = Field(None, description="Lucene search query to filter devices"),
include_relationships: bool = Field(False, description="Include relationship data")
) -> Dict[str, Any]:
"""List devices with filtering support"""
params = {
"page": page,
"per_page": per_page,
"relationships": include_relationships
}
if search_query:
params["q"] = search_query
if include_relationships:
params["include"] = True
return await make_request("GET", "/devices", params=params)
# Frameworks Tools (read-only)
@mcp.tool
async def list_frameworks(
page: int = Field(1, description="Page number for pagination"),
per_page: int = Field(100, description="Items per page (default: 100)"),
search_query: Optional[str] = Field(None, description="Lucene search query to filter frameworks"),
include_relationships: bool = Field(False, description="Include relationship data")
) -> Dict[str, Any]:
"""List compliance frameworks with filtering support"""
params = {
"page": page,
"per_page": per_page,
"relationships": include_relationships
}
if search_query:
params["q"] = search_query
if include_relationships:
params["include"] = True
return await make_request("GET", "/frameworks", params=params)
# Vendors Tools (read-only)
@mcp.tool
async def list_vendors(
page: int = Field(1, description="Page number for pagination"),
per_page: int = Field(100, description="Items per page (default: 100)"),
search_query: Optional[str] = Field(None, description="Lucene search query to filter vendors"),
include_relationships: bool = Field(False, description="Include relationship data")
) -> Dict[str, Any]:
"""List vendors (legacy) with filtering support"""
params = {
"page": page,
"per_page": per_page,
"relationships": include_relationships
}
if search_query:
params["q"] = search_query
if include_relationships:
params["include"] = True
return await make_request("GET", "/vendors", params=params)
# TPRM Vendors Tools (read-only)
@mcp.tool
async def list_tprm_vendors(
page: int = Field(1, description="Page number for pagination"),
per_page: int = Field(100, description="Items per page (default: 100)"),
search_query: Optional[str] = Field(None, description="Lucene search query to filter vendors"),
include_relationships: bool = Field(False, description="Include relationship data")
) -> Dict[str, Any]:
"""List TPRM vendors with filtering support"""
params = {
"page": page,
"per_page": per_page,
"relationships": include_relationships
}
if search_query:
params["q"] = search_query
if include_relationships:
params["include"] = True
return await make_request("GET", "/tprm/vendors", params=params)
# Integration Connections Tools (read-only)
@mcp.tool
async def list_integration_connections(
page: int = Field(1, description="Page number for pagination"),
per_page: int = Field(100, description="Items per page (default: 100)"),
search_query: Optional[str] = Field(None, description="Lucene search query to filter connections"),
include_relationships: bool = Field(False, description="Include relationship data")
) -> Dict[str, Any]:
"""List integration connections with filtering support"""
params = {
"page": page,
"per_page": per_page,
"relationships": include_relationships
}
if search_query:
params["q"] = search_query
if include_relationships:
params["include"] = True
return await make_request("GET", "/integration_connections", params=params)
# Repository Framework Scopes Tools (read-only)
@mcp.tool
async def list_repository_framework_scopes(
repository_id: str = Field(..., description="ID of the repository"),
include_relationships: bool = Field(False, description="Include relationship data")
) -> Dict[str, Any]:
"""List framework scopes for a repository"""
params = {}
if include_relationships:
params["include"] = True
return await make_request(
"GET",
f"/repositories/{repository_id}/framework_asset_scopes",
params=params
)
# User Accounts Tools (read-only)
@mcp.tool
async def list_user_accounts(
page: int = Field(1, description="Page number for pagination"),
per_page: int = Field(100, description="Items per page (default: 100)"),
search_query: Optional[str] = Field(None, description="Lucene search query to filter accounts"),
include_relationships: bool = Field(False, description="Include relationship data")
) -> Dict[str, Any]:
"""List user accounts with filtering support"""
params = {
"page": page,
"per_page": per_page,
"relationships": include_relationships
}
if search_query:
params["q"] = search_query
if include_relationships:
params["include"] = True
return await make_request("GET", "/user_accounts", params=params)
# Repositories Tools (read-only)
@mcp.tool
async def list_repositories(
page: int = Field(1, description="Page number for pagination"),
per_page: int = Field(100, description="Items per page (default: 100)"),
search_query: Optional[str] = Field(None, description="Lucene search query to filter repositories"),
include_relationships: bool = Field(False, description="Include relationship data")
) -> Dict[str, Any]:
"""List repositories with filtering support"""
params = {
"page": page,
"per_page": per_page,
"relationships": include_relationships
}
if search_query:
params["q"] = search_query
if include_relationships:
params["include"] = True
return await make_request("GET", "/repositories", params=params)
def main():
"""Run the MCP server"""
mcp.run()
if __name__ == "__main__":
main()