Repository navigation
Expand file tree
/
Copy pathurl.ts
More file actions
48 lines (42 loc) · 1.49 KB
/
Copy pathurl.ts
File metadata and controls
48 lines (42 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
export const DEFAULT_HOST = "https://app.last9.io"
export const MCP_SERVER_NAME = "last9"
/**
* Options accepted via the tuple form in opencode.json:
*
* "plugin": [["@last9/opencode-plugin", { "org": "<org-slug>" }]]
*/
export interface Last9PluginOptions {
/** Your Last9 org slug (the part after app.last9.io/ in your browser URL). */
org?: string
/** Full MCP endpoint URL. Overrides `org`; useful for self-hosted or preview environments. */
url?: string
}
/** Minimal structural types — keeps the plugin dependency-free and tolerant of opencode config evolution. */
export interface McpRemoteConfig {
type: "remote"
url: string
enabled: boolean
}
export interface OpenCodeConfig {
mcp?: Record<string, McpRemoteConfig>
skills?: { paths?: string[] }
}
/**
* Resolve the Last9 MCP endpoint.
*
* Precedence: explicit `url` option > `LAST9_MCP_URL` env >
* `org` option > `LAST9_ORG_SLUG` env > undefined (no injection).
*
* Lives outside the plugin entrypoint because opencode's loader requires
* every export of the entrypoint module to be a function.
*/
export function resolveMcpUrl(
options: Last9PluginOptions = {},
env: NodeJS.ProcessEnv = process.env,
): string | undefined {
const explicit = (options.url ?? env.LAST9_MCP_URL ?? "").trim()
if (explicit) return explicit.replace(/\/+$/, "")
const org = (options.org ?? env.LAST9_ORG_SLUG ?? "").trim()
if (!org) return undefined
return `${DEFAULT_HOST}/api/v4/organizations/${encodeURIComponent(org)}/mcp`
}