Skip to content

Commit d93b494

Browse files
committed
readme
1 parent 409c2b3 commit d93b494

File tree

5 files changed

+354
-96
lines changed

5 files changed

+354
-96
lines changed

AGENTS.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ If no new rule is detected -> do not update the file.
6868
- build: `dotnet build ManagedCode.MCPGateway.slnx -c Release --no-restore`
6969
- analyze: `dotnet build ManagedCode.MCPGateway.slnx -c Release --no-restore -p:RunAnalyzers=true`
7070
- test: `dotnet test --solution ManagedCode.MCPGateway.slnx -c Release --no-build`
71-
- pack: `dotnet pack src/ManagedCode.MCPGateway/ManagedCode.MCPGateway.csproj -c Release --no-build -o ./artifacts`
7271
- format: `dotnet format ManagedCode.MCPGateway.slnx`
7372
- skills-validate: `python3 .codex/skills/mcaf-skill-curation/scripts/validate_skills.py .codex/skills`
7473
- skills-metadata: `python3 .codex/skills/mcaf-skill-curation/scripts/generate_available_skills.py .codex/skills --absolute`
@@ -118,6 +117,9 @@ If no new rule is detected -> do not update the file.
118117

119118
- Update `README.md` whenever public API shape, setup, or usage changes.
120119
- Keep the README focused on package usage and onboarding, not internal implementation notes.
120+
- Document optional DI dependencies explicitly in README examples so consumers know which services they must register themselves, such as embedding generators.
121+
- Keep README code examples as real example code blocks, not commented-out pseudo-code; if behavior is optional, show it in a separate example instead of commenting lines inside another snippet.
122+
- Never leave empty placeholder setup blocks in README examples such as `// gateway configuration`; show a concrete minimal configuration that actually demonstrates the API.
121123
- Keep repo docs and skills in English to stay aligned with MCAF conventions.
122124
- Keep root packaging metadata centralized in `Directory.Build.props`.
123125
- Keep package versions centralized in `Directory.Packages.props`.
@@ -141,7 +143,6 @@ If no new rule is detected -> do not update the file.
141143
- restore
142144
- build
143145
- test
144-
- pack when package output is affected
145146

146147
### Code Style
147148

@@ -151,6 +152,7 @@ If no new rule is detected -> do not update the file.
151152
- Keep public API names aligned with package identity `ManagedCode.MCPGateway`.
152153
- Do not duplicate package metadata or version blocks inside project files unless a project-specific override is required.
153154
- Use constants for stable tool names and protocol-facing identifiers.
155+
- Never leave stable string literals inline in runtime code; extract named constants for diagnostic codes, messages, modes, keys, and other durable identifiers so changes stay centralized.
154156
- Keep transport-specific logic inside the gateway and source registration abstractions, not scattered across the codebase.
155157
- Keep the package dependency surface small and justified.
156158

README.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ var invoke = await gateway.InvokeAsync(new McpGatewayInvokeRequest(
7070
Query: "managedcode"));
7171
```
7272

73+
`AddManagedCodeMcpGateway(...)` does not create or configure an embedding generator for you. Vector ranking is enabled only when the same DI container also has an `IEmbeddingGenerator<string, Embedding<float>>`. The gateway first tries the keyed registration `McpGatewayServiceKeys.EmbeddingGenerator` and falls back to any regular registration. Otherwise it stays fully functional and uses lexical ranking.
74+
7375
## Context-Aware Search And Invoke
7476

7577
When the current turn has extra UI, workflow, or chat context, pass it through the request models:
@@ -127,7 +129,58 @@ These tools are useful when another model should first search the gateway catalo
127129
- required arguments
128130
- input schema summaries
129131

130-
If an embedding generator is registered, the gateway vectorizes those descriptor documents and uses cosine similarity plus a small lexical boost. If no embedding generator is present, it falls back to lexical ranking without disabling execution.
132+
If an embedding generator is registered, the gateway vectorizes those descriptor documents and uses cosine similarity plus a small lexical boost. It first tries the keyed registration `McpGatewayServiceKeys.EmbeddingGenerator` and then falls back to any regular `IEmbeddingGenerator<string, Embedding<float>>`. If no embedding generator is present, it falls back to lexical ranking without disabling execution.
133+
134+
The embedding generator is resolved per gateway operation, so singleton, scoped, and transient DI registrations all work with index builds and search.
135+
136+
## Optional Embeddings
137+
138+
Register any provider-specific implementation of `IEmbeddingGenerator<string, Embedding<float>>` in the same DI container before building the service provider.
139+
140+
Preferred registration for the gateway:
141+
142+
```csharp
143+
var services = new ServiceCollection();
144+
145+
services.AddKeyedSingleton<IEmbeddingGenerator<string, Embedding<float>>, MyEmbeddingGenerator>(
146+
McpGatewayServiceKeys.EmbeddingGenerator);
147+
148+
services.AddManagedCodeMcpGateway(options =>
149+
{
150+
options.AddTool(
151+
"local",
152+
AIFunctionFactory.Create(
153+
static (string query) => $"github:{query}",
154+
new AIFunctionFactoryOptions
155+
{
156+
Name = "github_search_repositories",
157+
Description = "Search GitHub repositories by user query."
158+
}));
159+
});
160+
```
161+
162+
Fallback when your app already exposes a regular embedding generator:
163+
164+
```csharp
165+
var services = new ServiceCollection();
166+
167+
services.AddSingleton<IEmbeddingGenerator<string, Embedding<float>>, MyEmbeddingGenerator>();
168+
169+
services.AddManagedCodeMcpGateway(options =>
170+
{
171+
options.AddTool(
172+
"local",
173+
AIFunctionFactory.Create(
174+
static (string query) => $"github:{query}",
175+
new AIFunctionFactoryOptions
176+
{
177+
Name = "github_search_repositories",
178+
Description = "Search GitHub repositories by user query."
179+
}));
180+
});
181+
```
182+
183+
The keyed registration is the preferred one, so you can dedicate a specific embedder to the gateway without affecting other app services.
131184

132185
## Supported Sources
133186

0 commit comments

Comments
 (0)