@cablate/mcp-google-map 0.0.2 → 0.0.3

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.
Files changed (2) hide show
  1. package/dist/index.cjs +57 -10
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -23471,7 +23471,7 @@ var DISTANCE_MATRIX_TOOL = {
23471
23471
  };
23472
23472
  var DIRECTIONS_TOOL = {
23473
23473
  name: "maps_directions",
23474
- description: "\u7372\u53D6\u5169\u9EDE\u4E4B\u9593\u7684\u8DEF\u7DDA\u6307\u5F15",
23474
+ description: "\u7372\u53D6\u5169\u9EDE\u4E4B\u9593\u7684\u8A73\u7D30\u5C0E\u822A\u8DEF\u7DDA",
23475
23475
  inputSchema: {
23476
23476
  type: "object",
23477
23477
  properties: {
@@ -23488,6 +23488,15 @@ var DIRECTIONS_TOOL = {
23488
23488
  enum: ["driving", "walking", "bicycling", "transit"],
23489
23489
  description: "\u4EA4\u901A\u6A21\u5F0F",
23490
23490
  default: "driving"
23491
+ },
23492
+ departure_time: {
23493
+ type: "string",
23494
+ description: "\u51FA\u767C\u6642\u9593",
23495
+ default: (/* @__PURE__ */ new Date()).toISOString()
23496
+ },
23497
+ arrival_time: {
23498
+ type: "string",
23499
+ description: "\u62B5\u9054\u6642\u9593"
23491
23500
  }
23492
23501
  },
23493
23502
  required: ["origin", "destination"]
@@ -23711,26 +23720,60 @@ var GoogleMapsTools = class {
23711
23720
  throw new Error("\u8A08\u7B97\u8DDD\u96E2\u77E9\u9663\u6642\u767C\u751F\u932F\u8AA4");
23712
23721
  }
23713
23722
  }
23714
- async getDirections(origin, destination, mode = "driving") {
23723
+ async getDirections(origin, destination, mode = "driving", departure_time, arrival_time) {
23715
23724
  try {
23725
+ let apiArrivalTime = void 0;
23726
+ if (arrival_time) {
23727
+ apiArrivalTime = Math.floor(arrival_time.getTime() / 1e3);
23728
+ }
23729
+ let apiDepartureTime = void 0;
23730
+ if (!apiArrivalTime) {
23731
+ if (departure_time instanceof Date) {
23732
+ apiDepartureTime = Math.floor(departure_time.getTime() / 1e3);
23733
+ } else if (departure_time) {
23734
+ apiDepartureTime = departure_time;
23735
+ } else {
23736
+ apiDepartureTime = "now";
23737
+ }
23738
+ }
23716
23739
  const response = await this.client.directions({
23717
23740
  params: {
23718
23741
  origin,
23719
23742
  destination,
23720
23743
  mode,
23721
23744
  language: this.defaultLanguage,
23722
- key: process.env.GOOGLE_MAPS_API_KEY || ""
23745
+ key: process.env.GOOGLE_MAPS_API_KEY || "",
23746
+ arrival_time: apiArrivalTime,
23747
+ departure_time: apiDepartureTime
23723
23748
  }
23724
23749
  });
23725
23750
  const result = response.data;
23726
23751
  if (result.status !== "OK") {
23727
- throw new Error(`\u8DEF\u7DDA\u6307\u5F15\u7372\u53D6\u5931\u6557: ${result.status}`);
23752
+ throw new Error(`\u8DEF\u7DDA\u6307\u5F15\u7372\u53D6\u5931\u6557: ${result.status} (arrival_time: ${apiArrivalTime}, departure_time: ${apiDepartureTime})`);
23728
23753
  }
23729
23754
  if (result.routes.length === 0) {
23730
23755
  throw new Error("\u627E\u4E0D\u5230\u8DEF\u7DDA");
23731
23756
  }
23732
23757
  const route = result.routes[0];
23733
23758
  const legs = route.legs[0];
23759
+ const formatTime = (timeInfo) => {
23760
+ if (!timeInfo || typeof timeInfo.value !== "number") return "";
23761
+ const date = new Date(timeInfo.value * 1e3);
23762
+ const options = {
23763
+ year: "numeric",
23764
+ month: "2-digit",
23765
+ day: "2-digit",
23766
+ hour: "2-digit",
23767
+ minute: "2-digit",
23768
+ second: "2-digit",
23769
+ hour12: false
23770
+ // Use 24-hour format
23771
+ };
23772
+ if (timeInfo.time_zone && typeof timeInfo.time_zone === "string") {
23773
+ options.timeZone = timeInfo.time_zone;
23774
+ }
23775
+ return date.toLocaleString(this.defaultLanguage.toString(), options);
23776
+ };
23734
23777
  return {
23735
23778
  routes: result.routes,
23736
23779
  summary: route.summary,
@@ -23741,11 +23784,13 @@ var GoogleMapsTools = class {
23741
23784
  total_duration: {
23742
23785
  value: legs.duration.value,
23743
23786
  text: legs.duration.text
23744
- }
23787
+ },
23788
+ arrival_time: formatTime(legs.arrival_time),
23789
+ departure_time: formatTime(legs.departure_time)
23745
23790
  };
23746
23791
  } catch (error) {
23747
23792
  console.error("Error in getDirections:", error);
23748
- throw new Error("\u7372\u53D6\u8DEF\u7DDA\u6307\u5F15\u6642\u767C\u751F\u932F\u8AA4");
23793
+ throw new Error("\u7372\u53D6\u8DEF\u7DDA\u6307\u5F15\u6642\u767C\u751F\u932F\u8AA4" + error);
23749
23794
  }
23750
23795
  }
23751
23796
  async getElevation(locations) {
@@ -23883,9 +23928,11 @@ var PlacesSearcher = class {
23883
23928
  };
23884
23929
  }
23885
23930
  }
23886
- async getDirections(origin, destination, mode = "driving") {
23931
+ async getDirections(origin, destination, mode = "driving", departure_time, arrival_time) {
23887
23932
  try {
23888
- const result = await this.mapsTools.getDirections(origin, destination, mode);
23933
+ const departureTime = departure_time ? new Date(departure_time) : /* @__PURE__ */ new Date();
23934
+ const arrivalTime = arrival_time ? new Date(arrival_time) : void 0;
23935
+ const result = await this.mapsTools.getDirections(origin, destination, mode, departureTime, arrivalTime);
23889
23936
  return {
23890
23937
  success: true,
23891
23938
  data: result
@@ -24040,8 +24087,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
24040
24087
  };
24041
24088
  }
24042
24089
  if (name === "maps_directions") {
24043
- const { origin, destination, mode } = args;
24044
- const result = await placesSearcher.getDirections(origin, destination, mode || "driving");
24090
+ const { origin, destination, mode, arrival_time, departure_time } = args;
24091
+ const result = await placesSearcher.getDirections(origin, destination, mode, departure_time, arrival_time);
24045
24092
  if (!result.success) {
24046
24093
  return {
24047
24094
  content: [{ type: "text", text: result.error || "\u7372\u53D6\u8DEF\u7DDA\u6307\u5F15\u5931\u6557" }],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cablate/mcp-google-map",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "esbuild src/index.ts --bundle --platform=node --outfile=dist/index.cjs --external:pdfreader --external:jsdom --external:mammoth --external:csv-parse --external:libreoffice-convert && shx chmod +x dist/index.cjs",