Skip to content

Commit 2421a2e

Browse files
jonathanMLDevzho
andauthored
deprecate legacy module facades (#168)
* deprecate legacy module facades * fixed link error --------- Co-authored-by: zho <jornathanm910923@gmail.com>
1 parent d6d80b4 commit 2421a2e

16 files changed

Lines changed: 339 additions & 82 deletions

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ Tagged releases are published to npm from GitHub Actions when a **GitHub Release
2727
- **Alliance CLI / `resolveAllianceConfig`:** When index or rerank env/CLI values are omitted, defaults remain `rag-hybrid` and `bge-reranker-v2-m3` (API-key-only MCP configs unchanged). See [examples/alliance/.env.example](examples/alliance/.env.example).
2828
- **Breaking (library):** Trimmed public re-exports — `buildQueryExperimental` and `buildGuidedQueryExperimental` removed from package root and `/alliance` entry. See [MIGRATION.md](docs/MIGRATION.md#unreleased-trimmed-library-exports).
2929

30+
### Deprecated
31+
32+
- Module-level singleton facades — use `ServerContext` instance methods via `createServer(config)` and `{ context: ctx }` at setup instead. Deprecated in the **next minor release** (see `[Unreleased]` until version is tagged); earliest removal **two minor releases later** per [deprecation-policy.md](docs/deprecation-policy.md#deprecation-window). Affected symbols: `getPineconeClient`, `setPineconeClient`, `clearPineconeClient`, `getServerConfig`, `setServerConfig`, `resetServerConfig`, `registerUrlGenerator`, `unregisterUrlGenerator`, `generateUrlForNamespace`, `hasUrlGenerator`, `resetUrlGenerationRegistry`, `markSuggested`, `requireSuggested`, `resetSuggestionFlow`, `getNamespacesWithCache`, `invalidateNamespacesCache`, `getDefaultServerContext`. See [MIGRATION.md § Legacy module-facade deprecations](docs/MIGRATION.md#unreleased-legacy-module-facade-deprecations) and [deprecation-policy.md](docs/deprecation-policy.md#active-deprecations-legacy-module-facades).
33+
3034
### Added
3135

3236
- Zod schemas for all nine MCP tool success responses (`queryResponseSchema`, `guidedQueryResponseSchema`, etc.) exported from the package root for client-side validation. Success payloads are runtime-validated before return.

README.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ npm install
9595
npm run build
9696
```
9797

98+
## Stability
99+
100+
This package ships as **`0.y.z`**. Under [semver §4](https://semver.org/spec/v2.0.0.html#spec-item-4), **minor versions may contain breaking changes** until `1.0.0`. Pin an exact version or use `~` (tilde) ranges — not `^` (caret) — until 1.0 to avoid absorbing breaking minors automatically.
101+
102+
Breaking changes include: type signature changes, tool schema changes, default behavior changes, and removed exports.
103+
104+
See [docs/deprecation-policy.md](docs/deprecation-policy.md) for the full deprecation window (minimum two minors before removal).
105+
98106
## Quick start
99107

100108
To try the server on **your own** Pinecone project (free tier, no Alliance index), follow [examples/quickstart/README.md](examples/quickstart/README.md): create two integrated-embedding indexes, copy [examples/quickstart/.env.example](examples/quickstart/.env.example), seed sample data, and run the MCP demo. Use an explicit `PINECONE_INDEX_NAME` in that flow rather than relying on Alliance default index names.
@@ -129,7 +137,7 @@ Each **`ServerContext`** owns its own suggest-flow gate, namespaces cache, URL g
129137

130138
Pass `config` at setup only when the context is not yet configured; after `createServer` + `setClient`, pass `{ context: ctx }` only.
131139

132-
Legacy module getters (`setPineconeClient`, `registerUrlGenerator`, etc.) still delegate to a process-default context when you omit `context` at setup.
140+
Module-level singleton facades (`setPineconeClient`, `registerUrlGenerator`, `getDefaultServerContext`, etc.) are **deprecated** — they delegate to a process-default context when you omit `context` at setup. Prefer explicit `ServerContext` per [Library embedding](#library-embedding). See [docs/deprecation-policy.md](docs/deprecation-policy.md#active-deprecations-legacy-module-facades).
133141

134142
### Library embedding
135143

@@ -145,21 +153,35 @@ ctx.setClient(new PineconeClient({ /* ... */ }));
145153
const server = await setupAllianceServer({ context: ctx });
146154
```
147155

148-
Use **`await using server = await setupAllianceServer({ context: ctx })`** for automatic teardown, or call **`ctx.teardown()`** when done. For legacy single-server flows that rely on the process-default context, **`teardownServer()`** resets that default before re-initializing.
156+
Use **`await using server = await setupAllianceServer({ context: ctx })`** for automatic teardown, or call **`ctx.teardown()`** when done.
149157

150158
For the **generic bridge only**, see [examples/quickstart/mcp-demo.ts](examples/quickstart/mcp-demo.ts). For the **full Alliance surface**, see [examples/alliance/library-embedding-demo.ts](examples/alliance/library-embedding-demo.ts) and [docs/TOOLS.md](docs/TOOLS.md#suggest-flow-gate).
151159

160+
#### Legacy (deprecated)
161+
162+
Process-default / facade-based setup remains available during the deprecation window (removal per [deprecation-policy.md](docs/deprecation-policy.md) — two minors after the deprecation minor):
163+
164+
```ts
165+
import { PineconeClient, setPineconeClient } from '@will-cppa/pinecone-read-only-mcp';
166+
import { resolveAllianceConfig, setupAllianceServer } from '@will-cppa/pinecone-read-only-mcp/alliance';
167+
168+
setPineconeClient(new PineconeClient({ /* ... */ }));
169+
const server = await setupAllianceServer(resolveAllianceConfig({ apiKey: '...' }));
170+
// Call teardownServer() before re-initializing the process-default context.
171+
```
172+
173+
Do not use this pattern for new code or multi-tenant embedding. See [docs/MIGRATION.md](docs/MIGRATION.md#unreleased-legacy-module-facade-deprecations).
174+
152175
### Custom URL generators
153176

154177
Namespaces other than `mailing` and `slack-Cpplang` (or different URL rules for any namespace) can use programmatic registration — no fork required.
155178

156-
Import `registerUrlGenerator` and types `UrlGeneratorFn` / `UrlGenerationResult` from `@will-cppa/pinecone-read-only-mcp`. Register **additional** namespaces before tools that emit URLs run. Built-in `mailing` / `slack-Cpplang` generators are installed by `setupAllianceServer` (not by `setupCoreServer`).
179+
Register **additional** namespaces on your `ServerContext` before tools that emit URLs run. Built-in `mailing` / `slack-Cpplang` generators are installed by `setupAllianceServer` (not by `setupCoreServer`).
157180

158181
```ts
159182
import {
160183
createServer,
161184
PineconeClient,
162-
registerUrlGenerator,
163185
type UrlGenerationResult,
164186
type UrlGeneratorFn,
165187
} from '@will-cppa/pinecone-read-only-mcp';
@@ -184,7 +206,7 @@ const myDocs: UrlGeneratorFn = (metadata): UrlGenerationResult => {
184206
: { url: null, method: 'unavailable', reason: 'doc_id missing' };
185207
};
186208

187-
registerUrlGenerator('product-docs', myDocs);
209+
ctx.registerUrlGenerator('product-docs', myDocs);
188210
```
189211

190212
A fuller embedding sample lives in [examples/alliance/custom-url-generator.ts](examples/alliance/custom-url-generator.ts).

docs/MIGRATION.md

Lines changed: 103 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,102 @@ When no experimental fields apply, the `experimental` key is **omitted** (not an
6969

7070
**Promotion:** Moving a field from `experimental` to stable requires CHANGELOG, TOOLS.md, and schema updates per [deprecation-policy.md § Stable vs experimental](./deprecation-policy.md#stable-vs-experimental-mcp-response-fields).
7171

72+
## Unreleased: Legacy module-facade deprecations
73+
74+
**Rationale:** Module-level singleton facades (`setPineconeClient`, `registerUrlGenerator`, `getDefaultServerContext`, etc.) delegate to a process-global `ServerContext`. They complicate multi-tenant embedding and hide initialization order. They are marked `@deprecated` in JSDoc; earliest removal is **two minor releases after** the deprecation minor (see [deprecation-policy.md § Deprecation window](./deprecation-policy.md#deprecation-window)).
75+
76+
**Who is affected:** Library embedders importing facade functions from `@will-cppa/pinecone-read-only-mcp` or `/alliance`.
77+
78+
**Recommended pattern:** `createServer(config)``ctx.setClient(...)``setupCoreServer({ context: ctx })` or `setupAllianceServer({ context: ctx })`.
79+
80+
### Client
81+
82+
**Before (deprecated):**
83+
84+
```ts
85+
import { PineconeClient, setPineconeClient } from '@will-cppa/pinecone-read-only-mcp';
86+
87+
setPineconeClient(new PineconeClient({ /* ... */ }));
88+
```
89+
90+
**After:**
91+
92+
```ts
93+
import { createServer, PineconeClient, resolveConfig } from '@will-cppa/pinecone-read-only-mcp';
94+
95+
const config = resolveConfig({ apiKey: '...', indexName: 'my-index' });
96+
const ctx = createServer(config);
97+
ctx.setClient(new PineconeClient({ /* ... */ }));
98+
```
99+
100+
### Config
101+
102+
**Before (deprecated):** `getServerConfig()` / `setServerConfig(config)` / `resetServerConfig()`.
103+
104+
**After:** `ctx.getConfig()` / `ctx.setConfig(config)` / `ctx.teardown()`.
105+
106+
### URL registry
107+
108+
**Before (deprecated):**
109+
110+
```ts
111+
import { registerUrlGenerator } from '@will-cppa/pinecone-read-only-mcp';
112+
113+
registerUrlGenerator('my-ns', myGenerator);
114+
```
115+
116+
**After:**
117+
118+
```ts
119+
ctx.registerUrlGenerator('my-ns', myGenerator);
120+
```
121+
122+
Same for `unregisterUrlGenerator`, `generateUrlForNamespace`, `hasUrlGenerator`, and `resetUrlGenerationRegistry``ctx.unregisterUrlGenerator`, `ctx.generateUrlForNamespace`, `ctx.hasUrlGenerator`, `ctx.resetUrlGenerators`.
123+
124+
### Suggest-flow gate
125+
126+
**Before (deprecated):** `markSuggested`, `requireSuggested`, `resetSuggestionFlow`.
127+
128+
**After:** `ctx.markSuggested`, `ctx.requireSuggested`, `ctx.resetSuggestionFlow`.
129+
130+
### Namespaces cache
131+
132+
**Before (deprecated):** `getNamespacesWithCache()`, `invalidateNamespacesCache()`.
133+
134+
**After:** `ctx.getNamespacesWithCache()`, `ctx.invalidateNamespacesCache()`.
135+
136+
### Process-default context
137+
138+
**Before (deprecated):**
139+
140+
```ts
141+
import { getDefaultServerContext, setupCoreServer } from '@will-cppa/pinecone-read-only-mcp';
142+
143+
await setupCoreServer(config); // uses process default
144+
const ctx = getDefaultServerContext();
145+
```
146+
147+
**After:**
148+
149+
```ts
150+
const ctx = createServer(config);
151+
ctx.setClient(client);
152+
await setupCoreServer({ context: ctx });
153+
```
154+
155+
### Teardown
156+
157+
**Before:** `teardownServer()` resets the process-default context.
158+
159+
**After:** `await ctx.teardown()` or `await using server = await setupAllianceServer({ context: ctx })` for automatic cleanup. `teardownServer()` remains available during the deprecation window for legacy single-server flows; prefer per-context lifecycle for new code.
160+
161+
### CLI and tests
162+
163+
- **CLI:** unchanged — the binary uses internal setup paths.
164+
- **Test fakes:** pass a dedicated `ServerContext` via `createIsolatedContext` or `createServer` + `{ context: ctx }` at setup instead of mutating process globals.
165+
166+
See [deprecation-policy.md § Active deprecations](./deprecation-policy.md#active-deprecations-legacy-module-facades) for the full inventory.
167+
72168
## Unreleased: trimmed library exports
73169

74170
**Who is affected:** Library embedders that imported `buildQueryExperimental` or `buildGuidedQueryExperimental` from `@will-cppa/pinecone-read-only-mcp` or `/alliance`.
@@ -86,11 +182,11 @@ import { buildQueryExperimental } from '@will-cppa/pinecone-read-only-mcp';
86182

87183
`PineconeClient.query()` return types (`HybridQueryResult`, etc.) and all Zod response schemas remain on the public surface.
88184

89-
## Unreleased: `ServerContext` instance APIs (phase 1)
185+
## Unreleased: `ServerContext` instance APIs (initial)
90186

91-
**Rationale:** Process-global singletons (Pinecone client slot, config, URL registry, suggest-flow gate, namespaces cache) complicate testing and multi-tenant embedding. Phase 1 introduces an opt-in **`ServerContext`** without removing legacy getters.
187+
**Rationale:** Process-global singletons (Pinecone client slot, config, URL registry, suggest-flow gate, namespaces cache) complicate testing and multi-tenant embedding. The initial milestone introduces an opt-in **`ServerContext`**; legacy module facades are deprecated (see [Legacy module-facade deprecations](#unreleased-legacy-module-facade-deprecations)).
92188

93-
**Now (0.2.x — unchanged for existing embedders):**
189+
**Deprecated (migrate before removal):**
94190

95191
```ts
96192
import { PineconeClient, setPineconeClient } from '@will-cppa/pinecone-read-only-mcp';
@@ -108,9 +204,9 @@ setPineconeClient(
108204
const server = await setupAllianceServer(config);
109205
```
110206

111-
Module-level helpers (`getPineconeClient`, `registerUrlGenerator`, `requireSuggested`, etc.) continue to work; they delegate to a process-default context.
207+
Module-level helpers (`getPineconeClient`, `registerUrlGenerator`, `requireSuggested`, etc.) still work during the deprecation window; they delegate to a process-default context.
112208

113-
**New (recommended — phase 4 explicit context at setup):** For one-shot client injection at construction, see [ServerContext composition API](#unreleased-servercontext-composition-api) (`createServer(config, { client })` or `createIsolatedContext`).
209+
**Recommended (instance-first):** For one-shot client injection at construction, see [ServerContext composition API](#unreleased-servercontext-composition-api) (`createServer(config, { client })` or `createIsolatedContext`).
114210

115211
```ts
116212
import { createServer, PineconeClient } from '@will-cppa/pinecone-read-only-mcp';
@@ -178,7 +274,7 @@ import { registerQueryTool, registerCountTool, registerListNamespacesTool } from
178274
registerQueryTool(server, ctx);
179275
```
180276

181-
**Later (future minors/major):** Legacy module getters will be marked `### Deprecated` per [deprecation-policy.md](./deprecation-policy.md).
277+
**Later:** Legacy module getters will be removed at the earliest removal minor per [deprecation-policy.md](./deprecation-policy.md).
182278

183279
See also [deprecation-policy.md § Future instance APIs](./deprecation-policy.md#future-instance-apis-servercontext).
184280

@@ -222,7 +318,7 @@ await setupCoreServer({ context: ctx });
222318

223319
Suggest-flow gate settings (`disableSuggestFlow`, `cacheTtlMs`) remain on `ServerConfig`, not on composition.
224320

225-
See also [ServerContext instance APIs (phase 1)](#unreleased-servercontext-instance-apis-phase-1) for legacy vs explicit-context setup.
321+
See also [ServerContext instance APIs (initial)](#unreleased-servercontext-instance-apis-initial) for legacy vs explicit-context setup.
226322

227323
---
228324

0 commit comments

Comments
 (0)