Skip to content

Commit edfaacb

Browse files
authored
Merge pull request #85 from maia-iyer/git_example_changes
πŸ“– Add example `.env` for github examples to run on Kagenti
2 parents 8b8c8f3 + af3cb21 commit edfaacb

6 files changed

Lines changed: 62 additions & 5 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
MCP_URL = "http://github-tool:8000/mcp"
2+
LOG_LEVEL = "DEBUG"
3+
JWKS_URI = "http://keycloak.keycloak.svc.cluster.local:8080/realms/master/protocol/openid-connect/certs"
4+
TASK_MODEL_ID = "ollama/ibm/granite4:latest"
5+
LLM_API_BASE = "http://host.docker.internal:11434"
6+
LLM_API_KEY = "ollama"
7+
MODEL_TEMPERATURE = 0
8+
SERVICE_PORT = 8000
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
TASK_MODEL_ID = "gpt-4.1-nano"
2+
MCP_URL = "http://github-tool:8000/mcp"
3+
LOG_LEVEL = "DEBUG"
4+
JWKS_URI = "http://keycloak.keycloak.svc.cluster.local:8080/realms/master/protocol/openid-connect/certs"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Github Issue Agent
2+
3+
## Introduction
4+
5+
The Github Issue Agent is designed to perform tasks dealing with Github issues, leveraging large language models (LLMs) to generate plans, execute steps, and summarize findings. This agent integrates with [the upstream Github MCP Server](https://github.com/github/github-mcp-server) as a tool via MCP and utilizes AI models for data extraction, summarization, and more. This agent also integrates with [this MCP Man-in-the-Middle](https://github.com/kagenti/agent-examples/tree/main/mcp/github_tool) that will verify OAuth tokens and can be configured with Github PATs to communicate with the upstream Github MPC Server.
6+
7+
## Architecture
8+
9+
<TODO>
10+
11+
### Configuration Variables
12+
13+
| Variable Name | Description | Required? | Default Value |
14+
|---------------|-------------|-----------|---------------|
15+
| LLM_API_BASE | The URL for OpenAI compatible API | Yes | `http://localhost:11434/v1` |
16+
| LLM_API_KEY | The API key for OpenAI compatible API | No | `my_api_key` |
17+
| TASK_MODEL_ID | The ID of the LLM | Yes | `granite3.3:8b` |
18+
| EXTRA_HEADERS | Extra headers for the OpenAI API, e.g. {"MY_HEADER": "my_value"} | No | `{}` |
19+
| MODEL_TEMPERATURE | The temperature for the model | Yes | `0` |
20+
| MCP_URL | Endpoint where the Slack MCP server can be found | No | "" |
21+
| SERVICE_PORT | Port on which the service will run | Yes | `8000` |
22+
| LOG_LEVEL | Application log level | No | DEBUG |
23+
| GITHUB_TOKEN | If set, will send requests to Github MCP Server with `Authorization: Bearer <GITHUB_TOKEN>` header. | No | - |
24+
| JWKS_URI | Endpoint to obtain JWKS for token validation. Enables token validation. | No | - |
25+
| ISSUER | Expected `iss` value of incoming bearer tokens | No | - |
26+
| TOKEN_URL | Endpoint to perform token exchange. Required for token exchange. | No | - |
27+
| CLIENT_ID | Client ID to authenticate to auth server with. Required for token exchange. Expected `aud` value of incoming bearer tokens | No | - |
28+
| CLIENT_SECRET | Client secret to authenticate to auth server with. Required for token exchange. | No | - |
29+
| TARGET_SCOPES | Requested scopes of token exchanged token | No | - |
30+
| TARGET_AUDIENCE | Requested audience of token exchanged token | No | - |
31+
32+
> **Note on Authorization configuration**
33+
> By default, no token validation is performed. To enable token validation, set `JWKS_URI`.
34+
> If `ISSUER` is additionally set, the `iss` claim will be checked to equal this value.
35+
> If all of `TOKEN_URL`, `CLIENT_ID`, and `CLIENT_SECRET` are set in addition, token exchange will be performed using Bearer tokens from incoming requests, to send to the MCP endpoint.
36+
> In addition to `TOKEN_URL`, `CLIENT_ID`, `CLIENT_SECRET`, which trigger token exchange, `TARGET_SCOPES` can be optionally configured to be the `scope` in the token exchange request.

β€Ža2a/git_issue_agent/a2a_agent.pyβ€Ž

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,12 @@ async def execute(self, context: RequestContext, event_queue: EventQueue):
138138
Returns:
139139
None
140140
"""
141-
if settings.JWKS_URI:
141+
if settings.GITHUB_TOKEN:
142+
user_token = settings.GITHUB_TOKEN
143+
elif settings.JWKS_URI:
142144
user_token = context.call_context.user._user.access_token
143145
else:
144-
user_token = settings.GITHUB_TOKEN
146+
raise Exception("either JWKS_URI or GITHUB_TOKEN env var must be set")
145147
user_input = [context.get_user_input()]
146148
task = context.current_task
147149
if not task:
@@ -222,8 +224,10 @@ def run():
222224
)
223225

224226
app = server.build() # this returns a Starlette app
225-
if not settings.JWKS_URI is None:
227+
if settings.JWKS_URI:
226228
logging.info("JWKS_URI is set - using JWT Validation middleware")
227-
app.add_middleware(AuthenticationMiddleware, backend=BearerAuthBackend(), on_error=on_auth_error)
229+
app.add_middleware(AuthenticationMiddleware, backend=BearerAuthBackend(), on_error=on_auth_error)
230+
elif settings.GITHUB_TOKEN is None:
231+
logging.error("One of JWKS_URI or GITHUB_TOKEN must be set.")
228232

229233
uvicorn.run(app, host="0.0.0.0", port=settings.SERVICE_PORT)

β€Ža2a/git_issue_agent/git_issue_agent/config.pyβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Settings(BaseSettings):
2828
)
2929
MCP_URL: str = Field(os.getenv("MCP_URL", "https://api.githubcopilot.com/mcp/"), description="Endpoint for an option MCP server")
3030
SERVICE_PORT: int = Field(os.getenv("SERVICE_PORT", 8000), description="Port on which the service will run.")
31-
GITHUB_TOKEN: str = Field(os.getenv("GITHUB_TOKEN", None), description="If not using agent with authorization, the default Github token to use")
31+
GITHUB_TOKEN: Optional[str] = Field(os.getenv("GITHUB_TOKEN", None), description="If not using agent with authorization, the default Github token to use")
3232

3333
# auth variables for token validation
3434
ISSUER: Optional[str] = Field(
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
UPSTREAM_MCP = "https://api.githubcopilot.com/mcp/"
2+
REQUIRED_SCOPE = "github-full-access"
3+
INIT_AUTH_HEADER = "Bearer <PRIVILEGED_ACCESS_PAT>"
4+
UPSTREAM_HEADER_TO_USE_IF_IN_AUDIENCE = "Bearer <PRIVILEGED_ACCESS_PAT>"
5+
UPSTREAM_HEADER_TO_USE_IF_NOT_IN_AUDIENCE = "Bearer <PUBLIC_ACCESS_PAT>"

0 commit comments

Comments
Β (0)