Skip to content

Commit da8a2b2

Browse files
author
Bas Alberts
committed
Update docs and finalize local streamable MCP server support
1 parent b262b92 commit da8a2b2

File tree

5 files changed

+68
-64
lines changed

5 files changed

+68
-64
lines changed

README.md

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,43 @@ It's primary value proposition is as a CLI tool that allows users to quickly def
1414

1515
Agents are defined through [personalities](personalities/), that receive a [task](taskflows/) to complete given a set of [tools](toolboxes/).
1616

17-
Agents can cooperate to complete sequences of tasks through so-called [Taskflows](taskflows/GRAMMAR.md).
17+
Agents can cooperate to complete sequences of tasks through so-called [taskflows](taskflows/GRAMMAR.md).
18+
19+
You can find a detailed overview of the taskflow grammar [here](https://github.com/GitHubSecurityLab/seclab-taskflow-agent/blob/main/taskflows/GRAMMAR.md) and example taskflows [here](https://github.com/GitHubSecurityLab/seclab-taskflow-agent/tree/main/taskflows/examples).
20+
21+
## Use Cases and Examples
22+
23+
The Seclab Taskflow Agent framework was primarily designed to fit the iterative feedback loop driven work involved in Agentic security research workflows and vulnerability triage tasks.
24+
25+
Its design philosophy is centered around the belief that a prompt level focus of capturing vulnerability patterns will greatly improve and scale security research results as frontier model capabilities evolve over time.
26+
27+
While the maintainer himself primarily uses this framework as a code auditing tool it also serves as a more generic swiss army knife for exploring Agentic workflows. For example, the GitHub Security Lab also uses this framework for automated code scanning alert triage.
28+
29+
The framework includes a [CodeQL](https://codeql.github.com/) MCP server that can be used for Agentic code review, see the [CVE-2023-2283](https://github.com/GitHubSecurityLab/seclab-taskflow-agent/blob/main/taskflows/CVE-2023-2283/CVE-2023-2283.yaml) for an example of how to have an Agent review C code using a CodeQL database.
30+
31+
Instead of generating CodeQL queries itself, the CodeQL MCP Server is used to provide CodeQL-query based MCP tools that allow an Agent to navigate and explore code. It leverages templated CodeQL queries to provide targeted context for model driven code analysis.
1832

1933
## Requirements
2034

2135
Python >= 3.9 or Docker
2236

23-
# Usage
37+
## Configuration
38+
39+
Provide a GitHub token for an account that is entitled to use GitHub Copilot via the `COPILOT_TOKEN` environment variable. Further configuration is use case dependent, i.e. pending which MCP servers you'd like to use in your taskflows.
40+
41+
You can set persisting environment variables via an `.env` file in the project root.
2442

25-
Provide a Copilot entitled GitHub PAT via the `COPILOT_TOKEN` environment variable.
43+
Example:
2644

27-
## Source
45+
```sh
46+
# Tokens
47+
COPILOT_TOKEN=<your_github_token>
48+
# MCP configs
49+
GITHUB_PERSONAL_ACCESS_TOKEN=<your_github_token>
50+
CODEQL_DBS_BASE_PATH="/app/my_data/"
51+
```
52+
53+
## Deploying from Source
2854

2955
First install the required dependencies:
3056

@@ -48,40 +74,42 @@ Example: deploying a Taskflow:
4874
python main.py -t example
4975
```
5076

51-
## Docker
77+
## Deploying from Docker
5278

53-
Alternatively you can deploy the Agent via its Docker image using `docker/run.sh`.
79+
You can deploy the Taskflow Agent via its Docker image using `docker/run.sh`.
80+
81+
WARNING: the Agent Docker image is _NOT_ intended as a security boundary but strictly a deployment convenience.
5482

5583
The image entrypoint is `main.py` and thus it operates the same as invoking the Agent from source directly.
5684

5785
You can find the Docker image for the Seclab Taskflow Agent [here](https://github.com/GitHubSecurityLab/seclab-taskflow-agent/pkgs/container/seclab-taskflow-agent) and how it is built [here](release_tools/).
5886

5987
Note that this image is based on a public release of the Taskflow Agent, and you will have to mount any custom taskflows, personalities, or prompts into the image for them to be available to the Agent.
6088

61-
See [docker/run.sh](docker/run.sh) for configuration details.
89+
Optional image mount points to supply custom data are configured via the environment:
6290

63-
Example: deploying a Taskflow:
91+
- Custom data via `MY_DATA`, mounts to `/app/my_data`
92+
- Custom personalities via `MY_PERSONALITIES`, mounts to `/app/personalities/my_personalities`
93+
- Custom taskflows via `MY_TASKFLOWS`, mounts to `/app/taskflows/my_taskflows`
94+
- Custom prompts via `MY_PROMPTS`, mounts to `/app/prompts/my_prompts`
95+
- Custom toolboxes via `MY_TOOLBOXES`, mounts to `/app/toolboxes/my_toolboxes`
96+
97+
See [docker/run.sh](docker/run.sh) for forther details details.
98+
99+
Example: deploying a Taskflow (example.yaml):
64100

65101
```sh
66102
docker/run.sh -t example
67103
```
68-
Example: deploying a custom taskflow:
104+
Example: deploying a custom taskflow (custom_taskflow.yaml_:
69105

70106
```sh
71107
MY_TASKFLOWS=~/my_taskflows docker/run.sh -t custom_taskflow
72108
```
73109

74-
Available image mount points are:
75-
76-
- Custom data via `MY_DATA` environment variable
77-
- Custom personalities via `MY_PERSONALITIES` environment variable
78-
- Custom taskflows via `MY_TASKFLOWS` environment variable
79-
- Custom prompts via `MY_PROMPTS` environment variable
80-
- Custom toolboxes via `MY_TOOLBOXES` environment variable
81-
82110
For more advanced scenarios like e.g. making custom MCP server code available, you can alter the run script to mount your custom code into the image and configure your toolboxes to use said code accordingly.
83111

84-
Example: custom MCP server deployment via Docker image:
112+
Example: a custom MCP server deployment via Docker image:
85113

86114
```sh
87115
export MY_MCP_SERVERS=./mcp_servers
@@ -109,7 +137,7 @@ docker run \
109137

110138
Our default run script makes the Docker socket available to the image, which contains the Docker cli, so 3rd party Docker based stdio MCP servers also function as normal.
111139

112-
Example: a toolbox configuration for the official GitHub MCP Server:
140+
Example: a toolbox configuration using the official GitHub MCP Server via Docker:
113141

114142
```yaml
115143
server_params:
@@ -120,23 +148,7 @@ server_params:
120148
GITHUB_PERSONAL_ACCESS_TOKEN: "{{ env GITHUB_PERSONAL_ACCESS_TOKEN }}"
121149
```
122150
123-
## Framework Configuration
124-
125-
Set environment variables via an `.env` file in the project root.
126-
127-
Example: a persistent Agent configuration with various MCP server environment variables set:
128-
129-
```sh
130-
# Tokens
131-
COPILOT_TOKEN=...
132-
# Docker config, MY_DATA is mounted to /app/my_data
133-
MY_DATA="/home/user/my_data"
134-
# MCP configs
135-
GITHUB_PERSONAL_ACCESS_TOKEN=...
136-
CODEQL_DBS_BASE_PATH="/app/my_data/"
137-
```
138-
139-
# Personalities
151+
## Personalities
140152
141153
Core characteristics for a single Agent. Configured through YAML files in `personalities/`.
142154

@@ -157,7 +169,7 @@ toolboxes:
157169
- echo
158170
```
159171

160-
# Toolboxes
172+
## Toolboxes
161173

162174
MCP servers that provide tools. Configured through YAML files in `toolboxes/`.
163175

@@ -174,18 +186,7 @@ server_params:
174186
SOME: value
175187
```
176188

177-
Example sse config:
178-
179-
```yaml
180-
server_params:
181-
kind: sse
182-
# make sure you .env config the echo server, see echo_sse.py for example
183-
url: http://127.0.0.1:9000/echo
184-
headers:
185-
SomeHeader: "{{ env USER }}"
186-
```
187-
188-
# Taskflows
189+
## Taskflows
189190

190191
A sequence of interdependent tasks performed by a set of Agents. Configured through a YAML based [grammar](taskflows/GRAMMAR.md) in [taskflows/](taskflows/).
191192

@@ -263,6 +264,6 @@ This project is licensed under the terms of the MIT open source license. Please
263264

264265
[SUPPORT](./SUPPORT.md)
265266

266-
## Acknowledgement
267+
## Acknowledgements
267268

268-
Security Lab team members @m-y-mo and @p- for contributing heavily to the testing and development of this framework, as well as the rest of the Security Lab team for helpful discussions and use cases.
269+
Security Lab team members [Man Yue Mo](https://github.com/m-y-mo) and [Peter Stockli](https://github.com/p-) for contributing heavily to the testing and development of this framework, as well as the rest of the Security Lab team for helpful discussions and feedback.

main.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ async def deploy_task_agents(agents: dict,
161161
def _print_out(line):
162162
msg = f"Streamable MCP Server stdout: {line}"
163163
logging.info(msg)
164-
print(msg)
164+
#print(msg)
165165
def _print_err(line):
166166
msg = f"Streamable MCP Server stderr: {line}"
167167
logging.info(msg)
168-
print(msg)
168+
#print(msg)
169169
server_proc = StreamableMCPThread(params['command'],
170170
url=params['url'],
171171
env=params['env'],
@@ -262,9 +262,6 @@ async def mcp_session_task(
262262
server_prompts=server_prompts,
263263
important_guidelines=important_guidelines)
264264
),
265-
# XXX: should handoffs have handoffs?
266-
# XXX: this would be a recursive chicken/egg problem :P
267-
# XXX: are initial handoff functions still visible to handoff agents in the run?
268265
handoffs=[],
269266
exclude_from_context=exclude_from_context,
270267
mcp_servers=[s[0] for s in mcp_servers],

mcp_servers/codeql/client.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ def _server_start(self):
7373
server_cmd += self.server_options
7474
self.stderr_log = open(self.stderr_log, 'a')
7575
p = subprocess.Popen(self.codeql_cli + server_cmd,
76+
text=True,
77+
bufsize=1,
78+
universal_newlines=True,
7679
stdin=subprocess.PIPE,
7780
stdout=subprocess.PIPE,
7881
stderr=self.stderr_log)
7982

80-
# XXX: should we give codeql query server some time to finish initializing ?
81-
# XXX: because the query server process is silent we can not just poll for some standard banner
82-
8383
# set some default callbacks for common notifications
8484
def _handle_ql_progressUpdated(params):
8585
print(f">> Progress: {params.get('step')}/{params.get('maxStep')} status: {params.get('message')}")
@@ -583,7 +583,7 @@ def run_query(query_path: str | Path, database: Path,
583583
progress_callback=None,
584584
template_values=None,
585585
# keep the query server alive if desired
586-
keep_alive=False,
586+
keep_alive=True,
587587
log_stderr=False):
588588
result = ''
589589
query_path = Path(query_path)
@@ -602,6 +602,7 @@ def run_query(query_path: str | Path, database: Path,
602602
bqrs_path = base_path / Path("query.bqrs")
603603
if search_paths:
604604
server.search_paths += search_paths
605+
605606
server._server_run_query_from_path(bqrs_path, query_path,
606607
quick_eval_pos=target_pos,
607608
template_values=template_values)
@@ -619,6 +620,6 @@ def run_query(query_path: str | Path, database: Path,
619620
result = server._bqrs_to_sarif(bqrs_path, server._query_info(query_path))
620621
case _:
621622
raise ValueError("Unsupported output format {fmt}")
622-
except BrokenPipeError as e:
623-
raise RuntimeError("Broken Pipe to query server") from e
623+
except Exception as e:
624+
raise RuntimeError(f"Error in run_query: {e}") from e
624625
return result

mcp_servers/codeql/mcp_server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ def _get_file_contents(db: str | Path, uri: str):
9595
def _run_query(query_name: str, database_path: str, language: str, template_values: dict):
9696
"""Run a CodeQL query and return the results"""
9797

98-
database_path = _resolve_db_path(database_path)
98+
try:
99+
database_path = _resolve_db_path(database_path)
100+
except RuntimeError:
101+
return json.dumps([f"The database pat for {database_path} could not be resolved"])
99102
try:
100103
query_path = _resolve_query_path(language, query_name)
101104
except RuntimeError:

mcp_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
# A process management class for running in-process MCP streamable servers
2222
class StreamableMCPThread(Thread):
23+
"""Process management for local streamable MCP servers"""
2324
def __init__(
2425
self,
2526
cmd,
@@ -35,7 +36,7 @@ def __init__(
3536
self.on_output = on_output
3637
self.on_error = on_error
3738
self.poll_interval = poll_interval
38-
self.env = os.environ.copy() # XXX: risk of leaking env secrets
39+
self.env = os.environ.copy() # XXX: potential for environment leak to MCP
3940
self.env.update(env)
4041
self._stop_event = Event()
4142
self.process = None
@@ -216,6 +217,7 @@ async def call_tool(self, *args, **kwargs):
216217
return result
217218

218219
class MCPNamespaceWrap:
220+
"""An MCP client object wrapper that provides us with namespace control"""
219221
def __init__(self, confirms, obj):
220222
self.confirms = confirms
221223
self._obj = obj

0 commit comments

Comments
 (0)