liveog 0.1.0 → 0.1.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/dist/mcp.d.ts CHANGED
@@ -6,6 +6,12 @@ type Msg = {
6
6
  method?: string;
7
7
  params?: Record<string, unknown>;
8
8
  };
9
+ /** Pages drawn for an agent may not reach the network or this machine's files: inline styles and
10
+ * scripts, data: pictures and Google Fonts only. */
11
+ export declare const CSP = "default-src 'none'; style-src 'unsafe-inline' https://fonts.googleapis.com; font-src data: https://fonts.gstatic.com; img-src data: blob:; script-src 'unsafe-inline'";
12
+ export declare function lockDown(html: string): string;
13
+ /** Where to save a cover: inside the project folder, never outside it. */
14
+ export declare function savePath(out: string, root?: string): string | null;
9
15
  /** One message in, its answer out (null for a notification). */
10
16
  export declare function reply(m: Msg, version: string): Promise<object | null>;
11
17
  export declare function serve(version: string, input?: NodeJS.ReadableStream, output?: NodeJS.WritableStream): void;
package/dist/mcp.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // what a good cover looks like is said once, in INSTRUCTIONS, which a client reads at the start.
3
3
  import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
4
4
  import { tmpdir } from 'node:os';
5
- import { isAbsolute, join, resolve } from 'node:path';
5
+ import { isAbsolute, join, relative, resolve } from 'node:path';
6
6
  import { createInterface } from 'node:readline';
7
7
  import { check, describe } from './check.js';
8
8
  import { draw } from './draw.js';
@@ -98,6 +98,23 @@ const TOOLS = [
98
98
  const VERSIONS = ['2025-06-18', '2025-03-26', '2024-11-05'];
99
99
  const text = (t, isError = false) => ({ content: [{ type: 'text', text: t }], ...(isError ? { isError } : {}) });
100
100
  const str = (x) => (typeof x === 'string' && x ? x : undefined);
101
+ /** Pages drawn for an agent may not reach the network or this machine's files: inline styles and
102
+ * scripts, data: pictures and Google Fonts only. */
103
+ export const CSP = "default-src 'none'; style-src 'unsafe-inline' https://fonts.googleapis.com; font-src data: https://fonts.gstatic.com; img-src data: blob:; script-src 'unsafe-inline'";
104
+ export function lockDown(html) {
105
+ const meta = `<meta http-equiv="Content-Security-Policy" content="${CSP}">`;
106
+ if (/<head[^>]*>/i.test(html))
107
+ return html.replace(/<head[^>]*>/i, (h) => h + meta);
108
+ if (/^\s*<!doctype[^>]*>/i.test(html))
109
+ return html.replace(/^\s*<!doctype[^>]*>/i, (d) => d + meta);
110
+ return meta + html;
111
+ }
112
+ /** Where to save a cover: inside the project folder, never outside it. */
113
+ export function savePath(out, root = process.cwd()) {
114
+ const file = resolve(root, out);
115
+ const rel = relative(resolve(root), file);
116
+ return rel && !rel.startsWith('..') && !isAbsolute(rel) ? file : null;
117
+ }
101
118
  function drawCover(args) {
102
119
  const title = str(args.title);
103
120
  const html = str(args.html);
@@ -106,6 +123,9 @@ function drawCover(args) {
106
123
  const out = str(args.out);
107
124
  if (out && !/\.png$/i.test(out))
108
125
  return text('out must end in .png.', true);
126
+ const saveAt = out ? savePath(out) : null;
127
+ if (out && !saveAt)
128
+ return text('out must be a path inside the project, e.g. public/og/home.png.', true);
109
129
  const words = { title: title ?? '' };
110
130
  for (const k of ['site', 'line', 'tag', 'art']) {
111
131
  const v = str(args[k]);
@@ -116,8 +136,8 @@ function drawCover(args) {
116
136
  const tmp = mkdtempSync(join(tmpdir(), 'liveog-mcp-'));
117
137
  try {
118
138
  const src = join(tmp, 'cover.html');
119
- writeFileSync(src, html ?? coverHtml(words, look));
120
- const file = out ? (isAbsolute(out) ? out : resolve(process.cwd(), out)) : join(tmp, 'cover.png');
139
+ writeFileSync(src, lockDown(html ?? coverHtml(words, look)));
140
+ const file = saveAt ?? join(tmp, 'cover.png');
121
141
  const s = draw(src, file);
122
142
  return {
123
143
  content: [
@@ -164,7 +184,13 @@ export async function reply(m, version) {
164
184
  }
165
185
  case 'ping': return ok({});
166
186
  case 'tools/list': return ok({ tools: TOOLS });
167
- case 'tools/call': return ok(await call(m.params?.name, (m.params?.arguments ?? {})));
187
+ case 'tools/call':
188
+ try {
189
+ return ok(await call(m.params?.name, (m.params?.arguments ?? {})));
190
+ }
191
+ catch (e) {
192
+ return ok(text(e.message, true));
193
+ }
168
194
  default: return { jsonrpc: '2.0', id: m.id, error: { code: -32601, message: `No method ${m.method}` } };
169
195
  }
170
196
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "liveog",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Link previews that stay current: Open Graph tags, covers drawn by a browser you already run, versioned cover addresses, privacy per link kind.",
5
5
  "keywords": [
6
6
  "open graph",