scrapeless-mcp-server 0.4.5 → 0.4.7

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.
@@ -0,0 +1,40 @@
1
+ import { Context } from "./context.js";
2
+ import { API_KEY } from "./config.js";
3
+ export class ContextManager {
4
+ static instance;
5
+ contexts;
6
+ constructor() {
7
+ this.contexts = new Map();
8
+ }
9
+ static getInstance() {
10
+ if (!ContextManager.instance) {
11
+ ContextManager.instance = new ContextManager();
12
+ }
13
+ return ContextManager.instance;
14
+ }
15
+ getContext(apiKey) {
16
+ const key = apiKey ?? API_KEY;
17
+ if (!this.contexts.has(key)) {
18
+ console.log(`Creating new Context for API key: ${key?.substring(0, 8)}...`);
19
+ this.contexts.set(key, new Context(key));
20
+ }
21
+ else {
22
+ console.log(`Reusing existing Context for API key: ${key?.substring(0, 8)}...`);
23
+ }
24
+ return this.contexts.get(key);
25
+ }
26
+ clearContext(apiKey) {
27
+ const key = apiKey ?? API_KEY;
28
+ if (this.contexts.has(key)) {
29
+ this.contexts.delete(key);
30
+ console.log(`Cleared Context for API key: ${key?.substring(0, 8)}...`);
31
+ }
32
+ }
33
+ clearAllContexts() {
34
+ this.contexts.clear();
35
+ console.log("Cleared all Contexts");
36
+ }
37
+ getContextCount() {
38
+ return this.contexts.size;
39
+ }
40
+ }
package/build/context.js CHANGED
@@ -5,7 +5,7 @@ export class Context {
5
5
  currentSessionId = "default-session-id";
6
6
  apiKey;
7
7
  constructor(apiKey) {
8
- this.sessionManager = new SessionManager();
8
+ this.sessionManager = SessionManager.getInstance();
9
9
  this.apiKey = apiKey;
10
10
  }
11
11
  getSession(id) {
@@ -0,0 +1,15 @@
1
+ {
2
+ "keep": {
3
+ "days": false,
4
+ "amount": 5
5
+ },
6
+ "auditLog": "logs/.8929a066e1e20cab48ddbfa9c509b48984514299-audit.json",
7
+ "files": [
8
+ {
9
+ "date": 1758002645284,
10
+ "name": "logs/scrapeless-2025-09-16.log",
11
+ "hash": "420a4884014fec02915075dd83086ff92cbd6584fe2157bf99056d478c1ce079"
12
+ }
13
+ ],
14
+ "hashType": "sha256"
15
+ }
package/build/server.js CHANGED
@@ -3,7 +3,7 @@ import { ScrapelessClient } from "@scrapeless-ai/sdk";
3
3
  import { SCRAPELESS_CONFIG, API_KEY } from "./config.js";
4
4
  import * as toolsList from "./tools/index.js";
5
5
  import * as browserTools from "./tools/browser/browser.js";
6
- import { Context } from "./context.js";
6
+ import { ContextManager } from "./context-manager.js";
7
7
  export const serverOptions = {
8
8
  name: "scrapeless-mcp-server",
9
9
  version: "0.2.0",
@@ -29,7 +29,7 @@ export const initMcpTools = (server, headers, apiKey) => {
29
29
  Object.values(toolsList).forEach((tool) => {
30
30
  server.tool(tool.name, tool.description, tool.inputSchema, (params) => tool.handle(params, getScrapelessClient()));
31
31
  });
32
- const context = new Context(apiKey ?? API_KEY);
32
+ const context = ContextManager.getInstance().getContext(apiKey ?? API_KEY);
33
33
  Object.values(browserTools).forEach((tool) => {
34
34
  server.tool(tool.name, tool.description, tool.inputSchema, async (params) => {
35
35
  const result = await context.run(tool, params, headers);
@@ -2,10 +2,17 @@ import { Scrapeless } from "@scrapeless-ai/sdk";
2
2
  import { getParamValue } from "@chatmcp/sdk/utils/index.js";
3
3
  import puppeteer from "puppeteer-core";
4
4
  export class SessionManager {
5
+ static instance;
5
6
  sessions;
6
7
  constructor() {
7
8
  this.sessions = new Map();
8
9
  }
10
+ static getInstance() {
11
+ if (!SessionManager.instance) {
12
+ SessionManager.instance = new SessionManager();
13
+ }
14
+ return SessionManager.instance;
15
+ }
9
16
  async createSession(id, apiKey, headers) {
10
17
  if (!this.sessions.has(id)) {
11
18
  this.sessions.set(id, { browser: null, page: null, closed: true });
@@ -35,6 +42,7 @@ export class SessionManager {
35
42
  session.closed = true;
36
43
  session.browser = null;
37
44
  session.page = null;
45
+ this.sessions.delete(id);
38
46
  });
39
47
  session.browser = browser;
40
48
  session.page = page;
@@ -1,7 +1,5 @@
1
- export * from './deepserp/googleFlights.js';
2
- export * from './deepserp/googleSearch.js';
3
- export * from './deepserp/googleTrends.js';
4
- export * from './deepserp/googleScholar.js';
5
- export * from './universal/scrapeHtml.js';
6
- export * from './universal/scrapeMarkdown.js';
7
- export * from './universal/scrapeScreenshot.js';
1
+ export * from "./deepserp/googleSearch.js";
2
+ export * from "./deepserp/googleTrends.js";
3
+ export * from "./universal/scrapeHtml.js";
4
+ export * from "./universal/scrapeMarkdown.js";
5
+ export * from "./universal/scrapeScreenshot.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scrapeless-mcp-server",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "bin": {