cograph-connect 0.1.0
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/LICENSE +201 -0
- package/README.md +43 -0
- package/dist/cli.js +164 -0
- package/dist/client-config.js +95 -0
- package/dist/config.js +105 -0
- package/dist/paths.js +38 -0
- package/dist/proxy.js +43 -0
- package/dist/remote.js +29 -0
- package/dist/skill.js +10 -0
- package/package.json +47 -0
- package/templates/codex-skill/SKILL.md +17 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Cograph contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
200
|
+
implied. See the License for the specific language governing permissions
|
|
201
|
+
and limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Cograph Connect
|
|
2
|
+
|
|
3
|
+
Connect Cograph to local agent clients through MCP and Codex skills.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx -y cograph-connect setup
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The setup command stores your Cograph URL and token locally, validates the
|
|
10
|
+
remote `/mcp/` endpoint, and can configure Claude Desktop, Cursor, and Codex
|
|
11
|
+
to launch a local stdio MCP proxy.
|
|
12
|
+
|
|
13
|
+
## What It Installs
|
|
14
|
+
|
|
15
|
+
- A local stdio MCP proxy named `cograph`.
|
|
16
|
+
- Client config entries for Claude Desktop, Cursor, and Codex.
|
|
17
|
+
- A Codex skill at `~/.codex/skills/cograph-connect`.
|
|
18
|
+
|
|
19
|
+
The Cograph token is stored outside client configs:
|
|
20
|
+
|
|
21
|
+
- macOS/Linux: `~/.config/cograph-connect/config.json`
|
|
22
|
+
- Windows: `%APPDATA%/cograph-connect/config.json`
|
|
23
|
+
|
|
24
|
+
On POSIX systems the config directory is written as `0700` and the config file
|
|
25
|
+
as `0600`.
|
|
26
|
+
|
|
27
|
+
## Token Scopes
|
|
28
|
+
|
|
29
|
+
Create a Cograph personal access token with:
|
|
30
|
+
|
|
31
|
+
- `mcp`
|
|
32
|
+
- `api:read`
|
|
33
|
+
|
|
34
|
+
## Commands
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
cograph-connect setup
|
|
38
|
+
cograph-connect status --check
|
|
39
|
+
cograph-connect config print
|
|
40
|
+
cograph-connect mcp --profile default
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Use `COGRAPH_CONNECT_TOKEN` to override the stored token for one command.
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import prompts from "prompts";
|
|
4
|
+
import { publicConfig, readConfig, redactToken, upsertProfile, } from "./config.js";
|
|
5
|
+
import { configureClient, manualSnippet, } from "./client-config.js";
|
|
6
|
+
import { configPath, packageRoot } from "./paths.js";
|
|
7
|
+
import { validateRemote } from "./remote.js";
|
|
8
|
+
import { installCodexSkill } from "./skill.js";
|
|
9
|
+
import { runMcpProxy } from "./proxy.js";
|
|
10
|
+
const CLIENTS = ["claude", "cursor", "codex"];
|
|
11
|
+
function parseClients(value) {
|
|
12
|
+
if (!value)
|
|
13
|
+
return undefined;
|
|
14
|
+
const parsed = value
|
|
15
|
+
.split(",")
|
|
16
|
+
.map((entry) => entry.trim().toLowerCase())
|
|
17
|
+
.filter(Boolean);
|
|
18
|
+
for (const client of parsed) {
|
|
19
|
+
if (!CLIENTS.includes(client)) {
|
|
20
|
+
throw new Error(`Unknown client: ${client}. Use: ${CLIENTS.join(", ")}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return parsed;
|
|
24
|
+
}
|
|
25
|
+
async function promptMissing(options) {
|
|
26
|
+
const questions = [];
|
|
27
|
+
if (!options.url) {
|
|
28
|
+
questions.push({
|
|
29
|
+
type: "text",
|
|
30
|
+
name: "url",
|
|
31
|
+
message: "Cograph URL",
|
|
32
|
+
initial: "http://localhost:8080",
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (!options.token) {
|
|
36
|
+
questions.push({
|
|
37
|
+
type: "password",
|
|
38
|
+
name: "token",
|
|
39
|
+
message: "Cograph PAT token",
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
let selectedClients = parseClients(options.clients);
|
|
43
|
+
if (!selectedClients && !options.yes) {
|
|
44
|
+
questions.push({
|
|
45
|
+
type: "multiselect",
|
|
46
|
+
name: "clients",
|
|
47
|
+
message: "Configure agent clients",
|
|
48
|
+
choices: [
|
|
49
|
+
{ title: "Claude Desktop", value: "claude", selected: true },
|
|
50
|
+
{ title: "Cursor", value: "cursor", selected: true },
|
|
51
|
+
{ title: "Codex", value: "codex", selected: true },
|
|
52
|
+
],
|
|
53
|
+
min: 0,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const answers = questions.length
|
|
57
|
+
? await prompts(questions, {
|
|
58
|
+
onCancel: () => {
|
|
59
|
+
throw new Error("Setup cancelled");
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
: {};
|
|
63
|
+
selectedClients =
|
|
64
|
+
selectedClients || (options.yes ? CLIENTS : (answers.clients ?? []));
|
|
65
|
+
return {
|
|
66
|
+
url: options.url || answers.url,
|
|
67
|
+
token: options.token || answers.token,
|
|
68
|
+
clients: selectedClients,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function printClientResult(result) {
|
|
72
|
+
const action = result.changed ? "configured" : "already configured";
|
|
73
|
+
console.log(`${result.client}: ${action} at ${result.path}`);
|
|
74
|
+
if (result.backupPath) {
|
|
75
|
+
console.log(`${result.client}: backup written to ${result.backupPath}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async function runSetup(options) {
|
|
79
|
+
const resolved = await promptMissing(options);
|
|
80
|
+
if (!resolved.url || !resolved.token) {
|
|
81
|
+
throw new Error("Both Cograph URL and token are required");
|
|
82
|
+
}
|
|
83
|
+
if (!options.noValidate) {
|
|
84
|
+
const count = await validateRemote({
|
|
85
|
+
url: resolved.url,
|
|
86
|
+
token: resolved.token,
|
|
87
|
+
});
|
|
88
|
+
console.log(`Validated remote MCP endpoint. Tools available: ${count}`);
|
|
89
|
+
}
|
|
90
|
+
const config = await upsertProfile({
|
|
91
|
+
profileName: options.profile,
|
|
92
|
+
url: resolved.url,
|
|
93
|
+
token: resolved.token,
|
|
94
|
+
});
|
|
95
|
+
const profile = config.profiles[options.profile];
|
|
96
|
+
console.log(`Saved profile "${options.profile}" to ${configPath()}`);
|
|
97
|
+
console.log(`Token: ${redactToken(profile.token)}`);
|
|
98
|
+
for (const client of resolved.clients) {
|
|
99
|
+
try {
|
|
100
|
+
printClientResult(await configureClient(client, options.profile));
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
104
|
+
console.error(`${client}: could not update config: ${message}`);
|
|
105
|
+
console.error(`Manual snippet:\n${manualSnippet(client, options.profile)}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (!options.noSkill) {
|
|
109
|
+
const target = await installCodexSkill({
|
|
110
|
+
packageRoot: packageRoot(import.meta.url),
|
|
111
|
+
});
|
|
112
|
+
console.log(`codex skill: installed at ${target}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
async function runStatus({ check }) {
|
|
116
|
+
const config = await readConfig();
|
|
117
|
+
if (!config) {
|
|
118
|
+
console.log("cograph-connect is not configured.");
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
console.log(JSON.stringify(publicConfig(config), null, 2));
|
|
122
|
+
if (check) {
|
|
123
|
+
const profile = config.profiles[config.defaultProfile];
|
|
124
|
+
const count = await validateRemote(profile);
|
|
125
|
+
console.log(`Remote MCP check passed. Tools available: ${count}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const program = new Command();
|
|
129
|
+
program
|
|
130
|
+
.name("cograph-connect")
|
|
131
|
+
.description("Connect Cograph to agent clients through MCP and Codex skills.")
|
|
132
|
+
.version("0.1.0");
|
|
133
|
+
program
|
|
134
|
+
.command("setup")
|
|
135
|
+
.description("Configure Cograph MCP access for local agent clients.")
|
|
136
|
+
.option("--url <url>", "Cograph base URL or /mcp/ URL")
|
|
137
|
+
.option("--token <token>", "Cograph PAT token")
|
|
138
|
+
.option("--profile <name>", "Profile name", "default")
|
|
139
|
+
.option("--clients <list>", "Comma-separated clients: claude,cursor,codex")
|
|
140
|
+
.option("-y, --yes", "Use defaults for unanswered choices")
|
|
141
|
+
.option("--no-validate", "Skip remote MCP validation")
|
|
142
|
+
.option("--no-skill", "Skip Codex skill installation")
|
|
143
|
+
.action(async (options) => runSetup(options));
|
|
144
|
+
program
|
|
145
|
+
.command("mcp")
|
|
146
|
+
.description("Run the local stdio MCP proxy.")
|
|
147
|
+
.option("--profile <name>", "Profile name")
|
|
148
|
+
.action(async ({ profile }) => runMcpProxy(profile));
|
|
149
|
+
program
|
|
150
|
+
.command("status")
|
|
151
|
+
.description("Print configured profiles with redacted tokens.")
|
|
152
|
+
.option("--check", "Validate the default profile against remote Cograph")
|
|
153
|
+
.action(async (options) => runStatus(options));
|
|
154
|
+
program
|
|
155
|
+
.command("config")
|
|
156
|
+
.description("Config utilities.")
|
|
157
|
+
.command("print")
|
|
158
|
+
.description("Print cograph-connect config with redacted tokens.")
|
|
159
|
+
.action(async () => runStatus({ check: false }));
|
|
160
|
+
program.parseAsync().catch((error) => {
|
|
161
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
162
|
+
console.error(message.replace(/Bearer\s+\S+/gi, "Bearer <redacted>"));
|
|
163
|
+
process.exitCode = 1;
|
|
164
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { clientConfigPath } from "./paths.js";
|
|
4
|
+
export const MCP_SERVER_NAME = "cograph";
|
|
5
|
+
export function mcpServerConfig(profile = "default") {
|
|
6
|
+
return {
|
|
7
|
+
command: "npx",
|
|
8
|
+
args: ["-y", "cograph-connect", "mcp", "--profile", profile],
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
async function backupIfExists(filePath) {
|
|
12
|
+
try {
|
|
13
|
+
await fs.stat(filePath);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
if (error.code === "ENOENT")
|
|
17
|
+
return undefined;
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
const backupPath = `${filePath}.bak.${new Date()
|
|
21
|
+
.toISOString()
|
|
22
|
+
.replace(/[:.]/g, "-")}`;
|
|
23
|
+
await fs.copyFile(filePath, backupPath);
|
|
24
|
+
return backupPath;
|
|
25
|
+
}
|
|
26
|
+
async function readTextIfExists(filePath) {
|
|
27
|
+
try {
|
|
28
|
+
return await fs.readFile(filePath, "utf8");
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (error.code === "ENOENT")
|
|
32
|
+
return null;
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function mergeJsonMcpConfig(raw, profile) {
|
|
37
|
+
const parsed = raw?.trim() ? JSON.parse(raw) : {};
|
|
38
|
+
const root = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
39
|
+
const record = root;
|
|
40
|
+
const existingServers = record.mcpServers &&
|
|
41
|
+
typeof record.mcpServers === "object" &&
|
|
42
|
+
!Array.isArray(record.mcpServers)
|
|
43
|
+
? record.mcpServers
|
|
44
|
+
: {};
|
|
45
|
+
record.mcpServers = {
|
|
46
|
+
...existingServers,
|
|
47
|
+
[MCP_SERVER_NAME]: mcpServerConfig(profile),
|
|
48
|
+
};
|
|
49
|
+
return `${JSON.stringify(record, null, 2)}\n`;
|
|
50
|
+
}
|
|
51
|
+
export function mergeCodexTomlConfig(raw, profile) {
|
|
52
|
+
const lines = (raw ?? "").split(/\r?\n/);
|
|
53
|
+
const output = [];
|
|
54
|
+
let skipping = false;
|
|
55
|
+
for (const line of lines) {
|
|
56
|
+
if (/^\s*\[mcp_servers\.cograph\]\s*$/.test(line)) {
|
|
57
|
+
skipping = true;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (skipping && /^\s*\[/.test(line)) {
|
|
61
|
+
skipping = false;
|
|
62
|
+
}
|
|
63
|
+
if (!skipping) {
|
|
64
|
+
output.push(line);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
while (output.length > 0 && output[output.length - 1] === "") {
|
|
68
|
+
output.pop();
|
|
69
|
+
}
|
|
70
|
+
const block = [
|
|
71
|
+
"[mcp_servers.cograph]",
|
|
72
|
+
'command = "npx"',
|
|
73
|
+
`args = ["-y", "cograph-connect", "mcp", "--profile", ${JSON.stringify(profile)}]`,
|
|
74
|
+
];
|
|
75
|
+
return `${output.length ? `${output.join("\n")}\n\n` : ""}${block.join("\n")}\n`;
|
|
76
|
+
}
|
|
77
|
+
export async function configureClient(client, profile, filePath = clientConfigPath(client)) {
|
|
78
|
+
const raw = await readTextIfExists(filePath);
|
|
79
|
+
const next = client === "codex"
|
|
80
|
+
? mergeCodexTomlConfig(raw, profile)
|
|
81
|
+
: mergeJsonMcpConfig(raw, profile);
|
|
82
|
+
if (raw === next) {
|
|
83
|
+
return { client, path: filePath, changed: false };
|
|
84
|
+
}
|
|
85
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
86
|
+
const backupPath = await backupIfExists(filePath);
|
|
87
|
+
await fs.writeFile(filePath, next, "utf8");
|
|
88
|
+
return { client, path: filePath, changed: true, backupPath };
|
|
89
|
+
}
|
|
90
|
+
export function manualSnippet(client, profile = "default") {
|
|
91
|
+
if (client === "codex") {
|
|
92
|
+
return mergeCodexTomlConfig("", profile).trimEnd();
|
|
93
|
+
}
|
|
94
|
+
return JSON.stringify({ mcpServers: { [MCP_SERVER_NAME]: mcpServerConfig(profile) } }, null, 2);
|
|
95
|
+
}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { configPath } from "./paths.js";
|
|
4
|
+
export function normalizeMcpUrl(input) {
|
|
5
|
+
const trimmed = input.trim();
|
|
6
|
+
if (!trimmed) {
|
|
7
|
+
throw new Error("Cograph URL is required");
|
|
8
|
+
}
|
|
9
|
+
const withScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(trimmed)
|
|
10
|
+
? trimmed
|
|
11
|
+
: `http://${trimmed}`;
|
|
12
|
+
const url = new URL(withScheme);
|
|
13
|
+
if (url.pathname === "/" || url.pathname === "") {
|
|
14
|
+
url.pathname = "/mcp/";
|
|
15
|
+
}
|
|
16
|
+
else if (url.pathname.endsWith("/mcp")) {
|
|
17
|
+
url.pathname = `${url.pathname}/`;
|
|
18
|
+
}
|
|
19
|
+
else if (!url.pathname.endsWith("/mcp/")) {
|
|
20
|
+
url.pathname = path.posix.join(url.pathname, "mcp/");
|
|
21
|
+
if (!url.pathname.endsWith("/")) {
|
|
22
|
+
url.pathname = `${url.pathname}/`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
url.search = "";
|
|
26
|
+
url.hash = "";
|
|
27
|
+
return url.toString();
|
|
28
|
+
}
|
|
29
|
+
export function redactToken(token) {
|
|
30
|
+
if (!token)
|
|
31
|
+
return "";
|
|
32
|
+
if (token.length <= 16)
|
|
33
|
+
return `${token.slice(0, 4)}…`;
|
|
34
|
+
return `${token.slice(0, 12)}…${token.slice(-6)}`;
|
|
35
|
+
}
|
|
36
|
+
export async function readConfig(filePath = configPath()) {
|
|
37
|
+
try {
|
|
38
|
+
const raw = await fs.readFile(filePath, "utf8");
|
|
39
|
+
const parsed = JSON.parse(raw);
|
|
40
|
+
if (!parsed || parsed.version !== 1 || typeof parsed.defaultProfile !== "string") {
|
|
41
|
+
throw new Error("Unsupported cograph-connect config format");
|
|
42
|
+
}
|
|
43
|
+
return parsed;
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (error.code === "ENOENT") {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export async function writeConfig(config, filePath = configPath()) {
|
|
53
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true, mode: 0o700 });
|
|
54
|
+
const body = `${JSON.stringify(config, null, 2)}\n`;
|
|
55
|
+
await fs.writeFile(filePath, body, { mode: 0o600 });
|
|
56
|
+
if (process.platform !== "win32") {
|
|
57
|
+
await fs.chmod(path.dirname(filePath), 0o700).catch(() => undefined);
|
|
58
|
+
await fs.chmod(filePath, 0o600).catch(() => undefined);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export async function upsertProfile({ profileName, url, token, filePath = configPath(), }) {
|
|
62
|
+
const existing = await readConfig(filePath);
|
|
63
|
+
const now = new Date().toISOString();
|
|
64
|
+
const config = existing ?? { version: 1, defaultProfile: profileName, profiles: {} };
|
|
65
|
+
const previous = config.profiles[profileName];
|
|
66
|
+
config.defaultProfile = profileName;
|
|
67
|
+
config.profiles[profileName] = {
|
|
68
|
+
url: normalizeMcpUrl(url),
|
|
69
|
+
token,
|
|
70
|
+
createdAt: previous?.createdAt ?? now,
|
|
71
|
+
updatedAt: now,
|
|
72
|
+
};
|
|
73
|
+
await writeConfig(config, filePath);
|
|
74
|
+
return config;
|
|
75
|
+
}
|
|
76
|
+
export function publicConfig(config) {
|
|
77
|
+
return {
|
|
78
|
+
version: config.version,
|
|
79
|
+
defaultProfile: config.defaultProfile,
|
|
80
|
+
profiles: Object.fromEntries(Object.entries(config.profiles).map(([name, profile]) => [
|
|
81
|
+
name,
|
|
82
|
+
{
|
|
83
|
+
url: profile.url,
|
|
84
|
+
token: redactToken(profile.token),
|
|
85
|
+
createdAt: profile.createdAt,
|
|
86
|
+
updatedAt: profile.updatedAt,
|
|
87
|
+
},
|
|
88
|
+
])),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export async function requireProfile(profileName) {
|
|
92
|
+
const config = await readConfig();
|
|
93
|
+
if (!config) {
|
|
94
|
+
throw new Error("cograph-connect is not configured. Run `cograph-connect setup`.");
|
|
95
|
+
}
|
|
96
|
+
const name = profileName || config.defaultProfile;
|
|
97
|
+
const profile = config.profiles[name];
|
|
98
|
+
if (!profile) {
|
|
99
|
+
throw new Error(`Profile not found: ${name}`);
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
...profile,
|
|
103
|
+
token: process.env.COGRAPH_CONNECT_TOKEN || profile.token,
|
|
104
|
+
};
|
|
105
|
+
}
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
export function configPath() {
|
|
5
|
+
if (process.env.COGRAPH_CONNECT_CONFIG) {
|
|
6
|
+
return path.resolve(process.env.COGRAPH_CONNECT_CONFIG);
|
|
7
|
+
}
|
|
8
|
+
if (process.platform === "win32") {
|
|
9
|
+
const base = process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming");
|
|
10
|
+
return path.join(base, "cograph-connect", "config.json");
|
|
11
|
+
}
|
|
12
|
+
const base = process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".config");
|
|
13
|
+
return path.join(base, "cograph-connect", "config.json");
|
|
14
|
+
}
|
|
15
|
+
export function clientConfigPath(client) {
|
|
16
|
+
const home = os.homedir();
|
|
17
|
+
switch (client) {
|
|
18
|
+
case "claude":
|
|
19
|
+
if (process.platform === "darwin") {
|
|
20
|
+
return path.join(home, "Library", "Application Support", "Claude", "claude_desktop_config.json");
|
|
21
|
+
}
|
|
22
|
+
if (process.platform === "win32") {
|
|
23
|
+
const base = process.env.APPDATA || path.join(home, "AppData", "Roaming");
|
|
24
|
+
return path.join(base, "Claude", "claude_desktop_config.json");
|
|
25
|
+
}
|
|
26
|
+
return path.join(home, ".config", "Claude", "claude_desktop_config.json");
|
|
27
|
+
case "cursor":
|
|
28
|
+
return path.join(home, ".cursor", "mcp.json");
|
|
29
|
+
case "codex":
|
|
30
|
+
return path.join(home, ".codex", "config.toml");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function codexSkillPath() {
|
|
34
|
+
return path.join(os.homedir(), ".codex", "skills", "cograph-connect");
|
|
35
|
+
}
|
|
36
|
+
export function packageRoot(metaUrl) {
|
|
37
|
+
return path.resolve(path.dirname(fileURLToPath(metaUrl)), "..");
|
|
38
|
+
}
|
package/dist/proxy.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
import { CallToolRequestSchema, GetPromptRequestSchema, ListPromptsRequestSchema, ListResourceTemplatesRequestSchema, ListResourcesRequestSchema, ListToolsRequestSchema, ReadResourceRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
import { requireProfile } from "./config.js";
|
|
5
|
+
import { closeRemote, connectRemote } from "./remote.js";
|
|
6
|
+
function proxiedCapabilities(client) {
|
|
7
|
+
const remote = client.getServerCapabilities();
|
|
8
|
+
const capabilities = {};
|
|
9
|
+
if (remote?.tools)
|
|
10
|
+
capabilities.tools = {};
|
|
11
|
+
if (remote?.resources)
|
|
12
|
+
capabilities.resources = {};
|
|
13
|
+
if (remote?.prompts)
|
|
14
|
+
capabilities.prompts = {};
|
|
15
|
+
return capabilities;
|
|
16
|
+
}
|
|
17
|
+
export async function runMcpProxy(profileName) {
|
|
18
|
+
const profile = await requireProfile(profileName);
|
|
19
|
+
let remote;
|
|
20
|
+
try {
|
|
21
|
+
remote = await connectRemote(profile);
|
|
22
|
+
const server = new Server({ name: "cograph", version: "0.1.0" }, {
|
|
23
|
+
capabilities: proxiedCapabilities(remote.client),
|
|
24
|
+
instructions: remote.client.getInstructions() ||
|
|
25
|
+
"Use Cograph to query indexed repositories, wiki pages, graph context, and markdown collections.",
|
|
26
|
+
});
|
|
27
|
+
server.setRequestHandler(ListToolsRequestSchema, (request) => remote.client.listTools(request.params));
|
|
28
|
+
server.setRequestHandler(CallToolRequestSchema, (request) => remote.client.callTool(request.params));
|
|
29
|
+
server.setRequestHandler(ListResourcesRequestSchema, (request) => remote.client.listResources(request.params));
|
|
30
|
+
server.setRequestHandler(ListResourceTemplatesRequestSchema, (request) => remote.client.listResourceTemplates(request.params));
|
|
31
|
+
server.setRequestHandler(ReadResourceRequestSchema, (request) => remote.client.readResource(request.params));
|
|
32
|
+
server.setRequestHandler(ListPromptsRequestSchema, (request) => remote.client.listPrompts(request.params));
|
|
33
|
+
server.setRequestHandler(GetPromptRequestSchema, (request) => remote.client.getPrompt(request.params));
|
|
34
|
+
const transport = new StdioServerTransport();
|
|
35
|
+
await server.connect(transport);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
39
|
+
process.stderr.write(`cograph-connect MCP proxy failed: ${message}\n`);
|
|
40
|
+
await (remote ? closeRemote(remote) : Promise.resolve());
|
|
41
|
+
process.exitCode = 1;
|
|
42
|
+
}
|
|
43
|
+
}
|
package/dist/remote.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
3
|
+
import { normalizeMcpUrl } from "./config.js";
|
|
4
|
+
export async function connectRemote({ url, token, }) {
|
|
5
|
+
const transport = new StreamableHTTPClientTransport(new URL(normalizeMcpUrl(url)), {
|
|
6
|
+
requestInit: {
|
|
7
|
+
headers: new Headers({
|
|
8
|
+
Authorization: `Bearer ${token}`,
|
|
9
|
+
}),
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
const client = new Client({ name: "cograph-connect", version: "0.1.0" }, { capabilities: {} });
|
|
13
|
+
await client.connect(transport);
|
|
14
|
+
return { client, transport };
|
|
15
|
+
}
|
|
16
|
+
export async function closeRemote(connection) {
|
|
17
|
+
await connection.transport.terminateSession().catch(() => undefined);
|
|
18
|
+
await connection.client.close().catch(() => undefined);
|
|
19
|
+
}
|
|
20
|
+
export async function validateRemote({ url, token, }) {
|
|
21
|
+
const connection = await connectRemote({ url, token });
|
|
22
|
+
try {
|
|
23
|
+
const result = await connection.client.listTools();
|
|
24
|
+
return result.tools.length;
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
await closeRemote(connection);
|
|
28
|
+
}
|
|
29
|
+
}
|
package/dist/skill.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { codexSkillPath } from "./paths.js";
|
|
4
|
+
export async function installCodexSkill({ packageRoot, target = codexSkillPath(), }) {
|
|
5
|
+
const source = path.join(packageRoot, "templates", "codex-skill");
|
|
6
|
+
await fs.mkdir(path.dirname(target), { recursive: true });
|
|
7
|
+
await fs.rm(target, { recursive: true, force: true });
|
|
8
|
+
await fs.cp(source, target, { recursive: true });
|
|
9
|
+
return target;
|
|
10
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cograph-connect",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Connect Cograph to agent clients through MCP and Codex skills.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"cograph-connect": "dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"templates",
|
|
13
|
+
"README.md",
|
|
14
|
+
"LICENSE"
|
|
15
|
+
],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=20"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.json",
|
|
21
|
+
"dev": "tsx src/cli.ts",
|
|
22
|
+
"prepack": "npm run build",
|
|
23
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"pack:dry": "npm pack --dry-run"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
29
|
+
"commander": "^14.0.2",
|
|
30
|
+
"prompts": "^2.4.2"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^24.10.1",
|
|
34
|
+
"@types/prompts": "^2.4.9",
|
|
35
|
+
"tsx": "^4.20.6",
|
|
36
|
+
"typescript": "^5.9.3",
|
|
37
|
+
"vitest": "^4.0.15"
|
|
38
|
+
},
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/mikekonan/cograph-connect.git"
|
|
42
|
+
},
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/mikekonan/cograph-connect/issues"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://github.com/mikekonan/cograph-connect#readme"
|
|
47
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cograph-connect
|
|
3
|
+
description: Use Cograph MCP when answering questions about indexed repositories, generated wiki pages, code search, markdown collections, architecture, or project documentation available through Cograph.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Cograph Connect
|
|
7
|
+
|
|
8
|
+
Use the configured Cograph MCP server for questions about indexed repositories,
|
|
9
|
+
generated wiki pages, code graph context, markdown collections, architecture,
|
|
10
|
+
and project documentation.
|
|
11
|
+
|
|
12
|
+
## Workflow
|
|
13
|
+
|
|
14
|
+
- Start by listing available repositories or collections when the target is not explicit.
|
|
15
|
+
- Prefer precise Cograph tools/resources over broad filesystem or web searches.
|
|
16
|
+
- Preserve provenance from Cograph responses in your answer when available.
|
|
17
|
+
- If Cograph returns an authorization error, ask the user to run `cograph-connect setup` with a token that has `mcp` and `api:read` scopes.
|