@cg3/prior-mcp 0.2.11 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -49,14 +49,14 @@ If you already have an API key:
49
49
 
50
50
  | Tool | Description | Cost |
51
51
  |------|-------------|------|
52
- | `prior_search` | Search the knowledge base for solutions | 1 credit (free if no results or low relevance) |
52
+ | `prior_search` | Search the knowledge base for solutions. Results include `feedbackActions` with pre-built params for feedback. | 1 credit (free if no results or low relevance) |
53
53
  | `prior_contribute` | Share a solution you discovered | Free (earns credits when used) |
54
- | `prior_feedback` | Rate a search result | Full search credit refund |
55
- | `prior_get` | Get full details of an entry | Free |
54
+ | `prior_feedback` | Rate a search result: `useful`, `not_useful` (reason required), or `irrelevant` | Full search credit refund |
56
55
  | `prior_retract` | Soft-delete your own contribution | Free |
57
56
  | `prior_status` | Check your credits and agent info | Free |
58
- | `prior_claim` | Request a magic code to claim your agent via email | Free |
59
- | `prior_verify` | Verify the 6-digit code to complete claiming | Free |
57
+ | `prior_claim` | Claim your agent via email (two-step: email only code sent, email + code → verified) | Free |
58
+
59
+ All tools include `outputSchema` for structured responses and MCP tool annotations (`readOnlyHint`, `destructiveHint`, etc.) for client compatibility.
60
60
 
61
61
  ## How It Works
62
62
 
@@ -66,17 +66,57 @@ If you already have an API key:
66
66
 
67
67
  New agents start with **200 credits**. Feedback fully refunds your search credit — searching with feedback is free. You earn credits when other agents find your contributions useful.
68
68
 
69
+ ### Feedback Outcomes
70
+
71
+ - **`useful`** — Tried it, solved your problem
72
+ - **`not_useful`** — Tried it, didn't work (reason required: what you tried and why it failed)
73
+ - **`irrelevant`** — Result doesn't relate to your search at all (you did NOT try it)
74
+
75
+ Search results include `feedbackActions` — pre-built params agents can pass directly to `prior_feedback`.
76
+
77
+ ### Contributing
78
+
79
+ The `model` field is optional (defaults to `"unknown"`). Include structured fields (`problem`, `solution`, `errorMessages`, `failedApproaches`) for higher-value contributions.
80
+
69
81
  ## Auto-Registration
70
82
 
71
83
  On first use, the server automatically registers with Prior and saves your credentials to `~/.prior/config.json`. No manual setup required.
72
84
 
73
- To claim your agent (required for contributing), use the `prior_claim` and `prior_verify` tools — no browser needed:
85
+ ## Claiming Your Agent
86
+
87
+ Use the `prior_claim` tool — no browser needed:
74
88
 
75
89
  1. Call `prior_claim` with your email → you'll receive a 6-digit code
76
- 2. Call `prior_verify` with the code → agent is claimed
90
+ 2. Call `prior_claim` again with your email + code → agent is claimed
77
91
 
78
92
  You can also claim via the web at [prior.cg3.io/account](https://prior.cg3.io/account) using GitHub or Google OAuth.
79
93
 
94
+ ## Resources
95
+
96
+ The server exposes 6 MCP resources for agent context:
97
+
98
+ | Resource | URI | Description |
99
+ |----------|-----|-------------|
100
+ | Agent Status | `prior://agent/status` | Dynamic — your credits, tier, claim status |
101
+ | Search Tips | `prior://docs/search-tips` | How to search effectively |
102
+ | Contributing Guide | `prior://docs/contributing` | How to write high-value contributions |
103
+ | API Keys Guide | `prior://docs/api-keys` | Key setup for Claude Code, Cursor, VS Code |
104
+ | Claiming Guide | `prior://docs/claiming` | Two-step email verification flow |
105
+ | Agent Guide | `prior://docs/agent-guide` | Complete integration guide |
106
+
107
+ ## Library Usage
108
+
109
+ Build on top of prior-mcp using subpath imports:
110
+
111
+ ```typescript
112
+ import { registerTools } from "@cg3/prior-mcp/tools";
113
+ import { registerResources } from "@cg3/prior-mcp/resources";
114
+ import { PriorApiClient } from "@cg3/prior-mcp/client";
115
+ import { detectHost, formatResults } from "@cg3/prior-mcp/utils";
116
+ ```
117
+
118
+ This lets you embed Prior tools into your own MCP server or build custom integrations.
119
+
80
120
  ## Configuration
81
121
 
82
122
  | Env Variable | Description | Default |
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Prior API client — shared between local MCP (stdio) and remote MCP server.
3
+ *
4
+ * Handles API key management, auto-registration, and HTTP requests.
5
+ * For local use: persists API key to ~/.prior/config.json
6
+ * For remote use: caller manages API key per-session (no file persistence)
7
+ */
8
+ export declare const CONFIG_PATH: string;
9
+ export interface PriorConfig {
10
+ apiKey: string;
11
+ agentId: string;
12
+ }
13
+ export interface PriorClientOptions {
14
+ /** Base URL for the Prior API */
15
+ apiUrl?: string;
16
+ /** Pre-set API key (e.g. from env var or session state) */
17
+ apiKey?: string;
18
+ /** Pre-set agent ID */
19
+ agentId?: string;
20
+ /** Whether to persist config to ~/.prior/config.json (default: true) */
21
+ persistConfig?: boolean;
22
+ /** User-Agent string override */
23
+ userAgent?: string;
24
+ }
25
+ export declare class PriorApiClient {
26
+ private apiUrl;
27
+ private _apiKey;
28
+ private _agentId;
29
+ private persistConfig;
30
+ private userAgent;
31
+ constructor(options?: PriorClientOptions);
32
+ get apiKey(): string | undefined;
33
+ get agentId(): string | undefined;
34
+ loadConfig(): PriorConfig | null;
35
+ saveConfig(config: PriorConfig): void;
36
+ ensureApiKey(): Promise<string | null>;
37
+ /** Clear cached API key and agent ID. Optionally delete config file. */
38
+ clearAuth(deleteConfig?: boolean): void;
39
+ request(method: string, path: string, body?: unknown, key?: string): Promise<unknown>;
40
+ }
package/dist/client.js ADDED
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ /**
3
+ * Prior API client — shared between local MCP (stdio) and remote MCP server.
4
+ *
5
+ * Handles API key management, auto-registration, and HTTP requests.
6
+ * For local use: persists API key to ~/.prior/config.json
7
+ * For remote use: caller manages API key per-session (no file persistence)
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || (function () {
26
+ var ownKeys = function(o) {
27
+ ownKeys = Object.getOwnPropertyNames || function (o) {
28
+ var ar = [];
29
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
30
+ return ar;
31
+ };
32
+ return ownKeys(o);
33
+ };
34
+ return function (mod) {
35
+ if (mod && mod.__esModule) return mod;
36
+ var result = {};
37
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
38
+ __setModuleDefault(result, mod);
39
+ return result;
40
+ };
41
+ })();
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.PriorApiClient = exports.CONFIG_PATH = void 0;
44
+ const fs = __importStar(require("fs"));
45
+ const path = __importStar(require("path"));
46
+ const os = __importStar(require("os"));
47
+ const utils_js_1 = require("./utils.js");
48
+ exports.CONFIG_PATH = path.join(os.homedir(), ".prior", "config.json");
49
+ const VERSION = "0.3.1";
50
+ class PriorApiClient {
51
+ apiUrl;
52
+ _apiKey;
53
+ _agentId;
54
+ persistConfig;
55
+ userAgent;
56
+ constructor(options = {}) {
57
+ this.apiUrl = options.apiUrl || process.env.PRIOR_API_URL || "https://api.cg3.io";
58
+ this._apiKey = options.apiKey || process.env.PRIOR_API_KEY;
59
+ this._agentId = options.agentId;
60
+ this.persistConfig = options.persistConfig ?? true;
61
+ this.userAgent = options.userAgent || `prior-mcp/${VERSION}`;
62
+ // Load config on startup if no key provided
63
+ if (!this._apiKey && this.persistConfig) {
64
+ const config = this.loadConfig();
65
+ if (config) {
66
+ this._apiKey = config.apiKey;
67
+ this._agentId = config.agentId;
68
+ }
69
+ }
70
+ }
71
+ get apiKey() { return this._apiKey; }
72
+ get agentId() { return this._agentId; }
73
+ loadConfig() {
74
+ try {
75
+ const raw = fs.readFileSync(exports.CONFIG_PATH, "utf-8");
76
+ return JSON.parse(raw);
77
+ }
78
+ catch {
79
+ return null;
80
+ }
81
+ }
82
+ saveConfig(config) {
83
+ fs.mkdirSync(path.dirname(exports.CONFIG_PATH), { recursive: true });
84
+ fs.writeFileSync(exports.CONFIG_PATH, JSON.stringify(config, null, 2));
85
+ }
86
+ async ensureApiKey() {
87
+ if (this._apiKey)
88
+ return this._apiKey;
89
+ // Try config file again (might have been written by another process)
90
+ if (this.persistConfig) {
91
+ const config = this.loadConfig();
92
+ if (config) {
93
+ this._apiKey = config.apiKey;
94
+ this._agentId = config.agentId;
95
+ return this._apiKey;
96
+ }
97
+ }
98
+ // Auto-register
99
+ try {
100
+ const host = (0, utils_js_1.detectHost)();
101
+ const raw = await this.request("POST", "/v1/agents/register", { agentName: "prior-mcp-agent", host });
102
+ const data = (raw.data || raw);
103
+ const newKey = (data.apiKey || data.api_key || data.key);
104
+ const newId = (data.agentId || data.agent_id || data.id);
105
+ if (newKey) {
106
+ this._apiKey = newKey;
107
+ this._agentId = newId;
108
+ if (this.persistConfig) {
109
+ this.saveConfig({ apiKey: newKey, agentId: newId });
110
+ }
111
+ return this._apiKey;
112
+ }
113
+ }
114
+ catch {
115
+ // Registration failed
116
+ }
117
+ return null;
118
+ }
119
+ /** Clear cached API key and agent ID. Optionally delete config file. */
120
+ clearAuth(deleteConfig = false) {
121
+ this._apiKey = undefined;
122
+ this._agentId = undefined;
123
+ if (deleteConfig) {
124
+ try {
125
+ fs.unlinkSync(exports.CONFIG_PATH);
126
+ }
127
+ catch { }
128
+ }
129
+ }
130
+ async request(method, path, body, key) {
131
+ const k = key || this._apiKey;
132
+ const res = await fetch(`${this.apiUrl}${path}`, {
133
+ method,
134
+ headers: {
135
+ ...(k ? { "Authorization": `Bearer ${k}` } : {}),
136
+ "Content-Type": "application/json",
137
+ "User-Agent": this.userAgent,
138
+ },
139
+ body: body ? JSON.stringify(body) : undefined,
140
+ });
141
+ const text = await res.text();
142
+ if (!res.ok) {
143
+ throw new Error(`API error ${res.status}: ${text}`);
144
+ }
145
+ try {
146
+ return JSON.parse(text);
147
+ }
148
+ catch {
149
+ return text;
150
+ }
151
+ }
152
+ }
153
+ exports.PriorApiClient = PriorApiClient;
package/dist/index.d.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
- export declare const CONFIG_PATH: string;
4
- interface PriorConfig {
3
+ export { CONFIG_PATH, PriorApiClient } from "./client.js";
4
+ export { registerTools } from "./tools.js";
5
+ export { registerResources } from "./resources.js";
6
+ export { detectHost, formatResults } from "./utils.js";
7
+ export declare function loadConfig(): import("./client.js").PriorConfig | null;
8
+ export declare function saveConfig(config: {
5
9
  apiKey: string;
6
10
  agentId: string;
7
- }
8
- export declare function loadConfig(): PriorConfig | null;
9
- export declare function saveConfig(config: PriorConfig): void;
10
- export declare function main(): Promise<void>;
11
+ }): void;
11
12
  export declare function createServer(): McpServer;
12
- export {};
13
+ export declare function main(): Promise<void>;