Ethanporath commited on
Commit
18c6f92
·
1 Parent(s): 521c696

updating docs

Browse files
.vscode/mcp.json CHANGED
@@ -1,7 +1,7 @@
1
  {
2
  "servers": {
3
  "ScribeMCP": {
4
- "url": "http://127.0.0.1:8000/mcp",
5
  "type": "sse"
6
  }
7
  },
 
1
  {
2
  "servers": {
3
  "ScribeMCP": {
4
+ "url": "https://eporath-scribe-mcp.hf.space/mcp",
5
  "type": "sse"
6
  }
7
  },
Dockerfile CHANGED
@@ -8,6 +8,8 @@ RUN pip install --no-cache-dir -r requirements.txt
8
 
9
  COPY . .
10
 
 
 
11
  EXPOSE 7860
12
 
13
- CMD ["uvicorn", "Scribe_app.main:app", "--host", "0.0.0.0", "--port", "7860"]
 
8
 
9
  COPY . .
10
 
11
+ RUN mkdir -p /app/tmp && chmod -R 777 /app/tmp
12
+
13
  EXPOSE 7860
14
 
15
+ CMD ["python", "-m", "uvicorn", "mcp_app.main:app", "--host", "0.0.0.0", "--port", "7860"]
mcp_app/endpointsAPI.py CHANGED
@@ -133,6 +133,39 @@ async def get_product_policy(product_name: str):
133
 
134
  @app.post("/vulnerabilities")
135
  async def query_vulnerabilities(input: dict):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  response = QueryResponse(
137
  format="",
138
  status=True,
 
133
 
134
  @app.post("/vulnerabilities")
135
  async def query_vulnerabilities(input: dict):
136
+ """
137
+ This tool is used to answer questions about vulnerabilities like: What are the vulnerabilities of my product? What are the vulnerabilities of a specific component? What are the vulnerabilities of a specific version of a component? Which products have a specific vulnerability, or a vulnerability with a specificy characteristic (such as has_key)
138
+
139
+ Args:
140
+ {
141
+ "column": [],
142
+ "filters" [],
143
+ "metrics" [],
144
+ "orderby": [],
145
+ "row_limit": 20
146
+ }
147
+ - "columns": list of columns to select. Use only these valid columns:
148
+ [('component_id', 'Dependency ID'), ('vulnerability_id', 'ID'), ('vector', 'Vector'), ('severity_string', 'Severity String'), ('base_severity_string', 'Base Severity String'), ('advisory_status', 'Advisory Status'), ('final_severity', 'Final Severity'), ('tool', 'Tool'), ('teamId', 'Teamid'), ('pipeline_run_id', 'Pipeline Run Id'), ('pkg', 'Pkg'), ('latest_package_version', 'Dependency Latest Version'), ('attestation_ids', 'Attestation IDs'), ('cvss_score', 'CVSS'), ('logical_app', 'Product'), ('vul_component_fixed_in_versions', 'Vulnerability Fix Version'), ('will_not_fix', 'Will Not Fix'), ('attestation_name', 'Attestation Name'), ('tag', 'Component Version'), ('targetName', 'Component'), ('base_score', 'Base Score'), ('source_layer', 'Layer'), ('text', 'Text'), ('is_latest_logical_version', 'Latest product version'), ('update', 'Update'), ('cwe_array', 'CWEs'), ('has_fix', 'Has Fix'), ('component_purl', 'Dependency PURL'), ('component_version', 'Dependency Version'), ('component_locations', 'Dependency Locations'), ('vul_date_changed', 'Vulnerability Last Change'), ('vul_component_created', 'Dependency Date'), ('epssProbability', 'EPSS'), ('vendor', 'Vendor'), ('direct_cwes', 'Direct Cwes'), ('advisory_modified', 'Advisory Modified'), ('hyper_links', 'Hyper Links'), ('advisory_text', 'Advisory Text'), ('cwes', 'CWE_Object'), ('advisory_justification', 'Advisory Justification'), ('component_dependency_type', 'Component Dependency Type'), ('cpes', 'Dependency CPEs'), ('has_kev', 'Has KEV'), ('version_timestamp', 'Version Timestamp'), ('severity', 'Original Severity'), ('epssPercentile', 'Epsspercentile'), ('epssScoreDate', 'Epssscoredate'), ('vul_adv_id', 'Vul Adv Id'), ('dependency_analysis', 'Dependency Analysis'), ('main_tool', 'Main Tool'), ('vul_published_on', 'Published'), ('vul_hyperlinks', 'References'), ('component_name', 'Dependency'), ('product_id', 'Product Id'), ('labels', 'Labels'), ('vul_source', 'Source'), ('targets', 'Targets'), ('logical_app_version', 'Version'), ('id', 'Id')]
149
+
150
+ - "filters": list of filter objects with keys:
151
+ - "col": column name (must be valid)
152
+ - "op": operator: ==, !=, >, <, >=, <=, in, not in, is null, is not null
153
+ - "val": filter value
154
+
155
+ - "metrics": list of metrics with keys:
156
+ - "label": output column name
157
+ - "expressionType": "SQL" or "SIMPLE"
158
+ - "sqlExpression": e.g. "COUNT(*)"
159
+
160
+ - "groupby": list of valid column names
161
+
162
+ - "orderby": list of [column_name, is_ascending_boolean]
163
+
164
+ - "row_limit": integer, max 30
165
+
166
+ Output ONLY the JSON object with no extra text.
167
+ """
168
+
169
  response = QueryResponse(
170
  format="",
171
  status=True,
mcp_app/main.py CHANGED
@@ -1,12 +1,13 @@
1
  from mcp_app.endpointsAPI import app
2
- from fastapi_mcp import FastApiMCP
3
  from pathlib import Path
4
  import json
5
 
 
6
  mcp = FastApiMCP(
7
  app,
8
  name="MCPEndpoints",
9
- description="Tools for querying data from Scribe database using FastAPI endpoints with MCP"
10
  )
11
 
12
 
 
1
  from mcp_app.endpointsAPI import app
2
+ from fastapi_mcp import FastApiMCP, t
3
  from pathlib import Path
4
  import json
5
 
6
+
7
  mcp = FastApiMCP(
8
  app,
9
  name="MCPEndpoints",
10
+ description="Tools for querying data from Scribe database using FastAPI endpoints with MCP",
11
  )
12
 
13
 
mcp_app/query.json CHANGED
@@ -1,17 +1,32 @@
1
  {
2
- "columns": ["rule_name"],
3
- "metrics": [
4
- {
5
- "label": "failure_count",
6
- "expressionType": "SQL",
7
- "sqlExpression": "COUNT(*)"
8
- }
9
- ],
10
- "filters": [
11
- { "col": "initiative_name", "op": "==", "val": "SSDF" },
12
- { "col": "message", "op": "==", "val": "fail" }
13
- ],
14
- "orderby": [["failure_count", false]],
15
- "groupby": ["rule_name"],
16
- "row_limit": 20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  }
 
1
  {
2
+ "columns": [
3
+ "vulnerability_id",
4
+ "cvss_score",
5
+ "epssProbability",
6
+ "has_kev"
7
+ ],
8
+ "filters": [
9
+ {
10
+ "col": "has_kev",
11
+ "op": "==",
12
+ "val": true
13
+ },
14
+ {
15
+ "col": "epssProbability",
16
+ "op": ">=",
17
+ "val": 0.1
18
+ }
19
+ ],
20
+ "metrics": [],
21
+ "orderby": [
22
+ [
23
+ "epssProbability",
24
+ false
25
+ ],
26
+ [
27
+ "cvss_score",
28
+ false
29
+ ]
30
+ ],
31
+ "row_limit": 5
32
  }
mcp_app/responseAPi.py CHANGED
@@ -1,20 +1,30 @@
1
  from openai import OpenAI
2
  from dotenv import load_dotenv
 
 
3
 
4
-
5
  load_dotenv()
6
 
7
  def main():
8
  client = OpenAI()
 
 
 
 
 
 
9
  response = client.responses.create(
10
  model= "gpt-4o",
11
  tools= [{
12
  "type": "mcp",
13
- "server_label": "fastAPIEndpoints",
14
- "server_url": "https://eporath-scribe-client-mcp.hf.space/mcp",
15
  "require_approval": "never",
16
  }],
17
- input = "get me a list of products"
 
 
18
  )
19
  print(response.output_text)
20
 
 
1
  from openai import OpenAI
2
  from dotenv import load_dotenv
3
+ from pathlib import Path
4
+ import json
5
 
6
+ readPath = Path(__file__).parent / "toolsDescriptions/tool_docs.json"
7
  load_dotenv()
8
 
9
  def main():
10
  client = OpenAI()
11
+
12
+ with open(readPath, "r") as f:
13
+ tool_description = json.load(f)
14
+ instructions = "Tool usage guidance:\n" + json.dumps(tool_description, indent=2)
15
+
16
+
17
  response = client.responses.create(
18
  model= "gpt-4o",
19
  tools= [{
20
  "type": "mcp",
21
+ "server_label": "ScribeMCP",
22
+ "server_url": "https://eporath-scribe-mcp.hf.space/mcp",
23
  "require_approval": "never",
24
  }],
25
+ input = "Query the vulnerabilities table for the top 5 risky CVEs - KEV vulnerabilities and vulnerabilities with highest EPSS scores."
26
+ #"Query the vulnerabilities table, for each vulnerability to get the list of affected products.",
27
+ #instructions = instructions
28
  )
29
  print(response.output_text)
30
 
mcp_app/testEndpoint.py CHANGED
@@ -15,7 +15,7 @@ class QueryString(BaseModel):
15
  def test_queries(payload):
16
  types_of_queries = ["vulnerabilities"]
17
  for item in types_of_queries:
18
- url = f"http://127.0.0.1:8000/policy"
19
  response = requests.post(url, json=payload)
20
  print("Status code:", response.status_code)
21
  try:
 
15
  def test_queries(payload):
16
  types_of_queries = ["vulnerabilities"]
17
  for item in types_of_queries:
18
+ url = f"https://eporath-scribe-mcp.hf.space/vulnerabilities"
19
  response = requests.post(url, json=payload)
20
  print("Status code:", response.status_code)
21
  try:
mcp_app/toolsDescriptions/updateToolDocs.py CHANGED
@@ -52,6 +52,15 @@ def updateTables():
52
  with open(queryTables, "w") as f:
53
  json.dump(tables, fp=f, indent=2)
54
 
 
 
 
 
 
 
 
 
 
55
  def updateToolDescription():
56
  with open(queryExamples, "r") as f:
57
  examples = json.load(f)
@@ -83,4 +92,4 @@ def parseDoc():
83
  updateToolDescription()
84
 
85
  if __name__ == "__main__":
86
- updateToolDescription()
 
52
  with open(queryTables, "w") as f:
53
  json.dump(tables, fp=f, indent=2)
54
 
55
+ def getTables(key: str):
56
+ with open(retrieveTables, "r") as f:
57
+ res = []
58
+ data = json.load(f)
59
+ for item in data[key]["columns"]:
60
+ res.append((item["column_name"], item["label"]))
61
+ return res
62
+
63
+
64
  def updateToolDescription():
65
  with open(queryExamples, "r") as f:
66
  examples = json.load(f)
 
92
  updateToolDescription()
93
 
94
  if __name__ == "__main__":
95
+ print(getTables("API Vulnerabilities"))
requirements.txt CHANGED
@@ -2,9 +2,11 @@ asttokens==3.0.0
2
  certifi==2025.1.31
3
  charset-normalizer==3.4.1
4
  decorator==5.2.1
 
5
  exceptiongroup==1.3.0
6
  executing==2.2.0
7
  fastapi==0.116.1
 
8
  idna==3.10
9
  ipython==8.37.0
10
  jedi==0.19.2
 
2
  certifi==2025.1.31
3
  charset-normalizer==3.4.1
4
  decorator==5.2.1
5
+ dotenv==0.9.9
6
  exceptiongroup==1.3.0
7
  executing==2.2.0
8
  fastapi==0.116.1
9
+ fastapi_mcp==0.3.7
10
  idna==3.10
11
  ipython==8.37.0
12
  jedi==0.19.2